How can I UN-attach media from a post?

I learned from Brian Fegter that you can Un-attach an image from a post while participating in this question: Can I attach an image to a different post? It isn’t exactly “simple”, but not to difficult. It’s the only solution I’ve been able to find.

media_handle_upload for local files?

You want media_handle_sideload() Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). // Array similar to a $_FILES upload array. $file_array = array( ‘name’ => ‘filename.jpg’, ‘tmp_name’ => ‘path/to/filename.jpg’, ); // Post ID to attach upload to, 0 for none. $post_id = 0; $attachment_id = media_handle_sideload( $file_array, $post_id … Read more

Find the post an attachment is attached to

So, if you start with this: $all_images = get_posts( array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ) ); Then $all_images is an array of objects. Step through each one: foreach ( $all_images as $image ) {} Inside that foreach, you can use the normal parameters available to the $post object: $image->ID is the ID of … Read more

get_the_post_thumbnail() doesn’t taking style attribute

get_the_post_thumbnail attribute array doesn’t know STYLE , the fields that are available for you to use are: src class alt title so just use the class and define you class to it: $attr = array( ‘title’ => get_the_title(), ‘alt’ => get_the_title(), ‘class’ => ‘rss_thumb’ ); $thumb = get_the_post_thumbnail($post->ID, ‘large-thumb’, $attr); and then define the style … Read more