WordPress.org

Ready to get started?Download WordPress

Forums

Detach & Re-Attach Media Attachment Images from Posts (21 posts)

  1. mkormendy
    Member
    Posted 4 years ago #

    Is there a way to 1. detach and 2. reattach attachment-images from one post to another post?

    There are two very common ways of uploading an image to WordPress to place it into the Media Gallery.

    1. Via "add New" under the Media Tab in the admin.
    2. Inserting an image when writing a post and uploading the image from the overlay Media window/layer.

    On upload alone, the first method does NOT attach the uploaded image to any particular post, but one manually attaches it later.
    The second method attaches the uploaded image to the post it was uploaded through.

    When I use the first method, there is a way to sort the listing for "unattached images" which you can select and then attach to a particular post. However, there is no way afterwards, to detach and re-attach an image, without altogether deleting that image from the Media gallery and re-uploading it and attaching it to a different post.

    This is an entirely inefficient process, and while I appreciate all of the hard work that the WordPress team is putting in to making WordPress have media-gallery abilities, I think that a native WordPress option to detach and re-attach images to posts should be inserted into the base code to complete this functionality already half-offered.

    In the meantime, does anyone know of a plugin, php script or coding approach to attach, detach and reattach/re-assign images within the Media gallery that WordPress already has built into it?

  2. mkormendy
    Member
    Posted 4 years ago #

    Oh as well, it would be nice if we could assign/attach one image to multiple posts.

  3. verticalbones
    Member
    Posted 4 years ago #

    I'm looking to resolve the same issue.

  4. jimmit
    Member
    Posted 4 years ago #

    Bump... Same here.

  5. olohanz
    Member
    Posted 4 years ago #

    Ineed, detaching/reattaching and attaching to multiple posts would be great features.

  6. zpingw
    Member
    Posted 4 years ago #

    facing the same problem here, hope to see an improvement on next update.

  7. Mansur
    Member
    Posted 4 years ago #

    Hope this will enhanced on next release...

    I want attach image to a post... but not inserted into post..
    and i will call that image to post via attachment calling function...

    It will make easy for photo album site, and make a gallery per post..

  8. Xamataca
    Member
    Posted 4 years ago #

    Oh as well, it would be nice if we could assign/attach one image to multiple posts

    This would be awesome, think of a multilingual site (you have duplicated post in each language and you can attach the same image to both).

  9. Robert Chapin
    Member
    Posted 4 years ago #

    BUMP!!

  10. Robert Chapin
    Member
    Posted 4 years ago #

  11. Aldi
    Member
    Posted 4 years ago #

    This plug-in (below) is the best I can find to handle detaching attachments. But you could only do it in the Library page, though.

    WordPress Media Library Plugin

  12. thecoup
    Member
    Posted 4 years ago #

    The ticket in trac has been downgraded and will likely linger.

    It's a pretty important but simple feature for managing media rich sites.

  13. cspiegl
    Member
    Posted 4 years ago #

    For me this featur would really be important and I can't imagine why it is not already there? For me this sounds much more important than a builtin image-editor?

    Maybe I'll try to write a plugin to do that detach thing.

  14. Daiv Mowbray
    Member
    Posted 4 years ago #

    That WordPress Media Library Plugin looks great, mixed with Faster Image Insert and superslider-media-pop which adds all available image sizes to the insert image panel.

    Unfortunately the WordPress Media Library Plugin doesn't work yet in WP version 3.0, at least not the de-attach function.

  15. sjogro
    Member
    Posted 4 years ago #

    I'd really like to be able to create a custom gallery from the files in my media library at any time. Multiple galleries per post as well. Wouldn't that be a more logical approach anyway?

  16. jimisaacs
    Member
    Posted 4 years ago #

    There is a ticket for the idea of the original concept of this thread in the trac.

  17. travis.hill
    Member
    Posted 4 years ago #

    +1 for detaching/reattaching and attaching to multiple posts - this should be native. Why can't I attach one image to multiple posts?

  18. Andy Potanin
    Member
    Posted 4 years ago #

    Post this into your functions.php file, or a plugin file, and a new column will be created on the media page that will allow you to "re-attach".

    add_filter("manage_upload_columns", 'upload_columns');
    add_action("manage_media_custom_column", 'media_custom_columns', 0, 2);
    
    function upload_columns($columns) {
    
    	unset($columns['parent']);
    	$columns['better_parent'] = "Parent";
    
    	return $columns;
    
    }
     function media_custom_columns($column_name, $id) {
    
    	$post = get_post($id);
    
    	if($column_name != 'better_parent')
    		return;
    
    		if ( $post->post_parent > 0 ) {
    			if ( get_post($post->post_parent) ) {
    				$title =_draft_or_post_title($post->post_parent);
    			}
    			?>
    			<strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?>
    			<br />
    			<a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Re-Attach'); ?></a></td>
    
    			<?php
    		} else {
    			?>
    			<?php _e('(Unattached)'); ?><br />
    			<a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a>
    			<?php
    		}
    
    }
  19. Andy Potanin
    Member
    Posted 4 years ago #

    Let me know if there are any problems with that code, I wrote it just now, didn't fully test it. Good luck!

  20. Drew Strojny
    Member
    Posted 4 years ago #

    Wow, thanks Andy. You are my hero :)

    We are working on a new photography theme and this is *exactly* what I was looking for. Well done!

  21. Mark Rowatt Anderson
    Member
    Posted 3 years ago #

    Very helpful - thanks Andy. I think you have a stray '<td>' at the end of this line:-

    <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Re-Attach'); ?></a></td>

    It would be great to also have a link to completely detach an image from a post. Any idea what the best way to do that would be?

Topic Closed

This topic has been closed to new replies.

About this Topic