WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] "Insert into Post" embeds link but fails to create attachment (8 posts)

  1. nsitu
    Member
    Posted 2 years ago #

    When I click "Insert into Post" it only works partly: a link to the file is properly embedded, but the file does NOT become attached to the post (or visible in the Gallery tab). The problem only exists for items already in the Media Library. In the context of a NEW upload, there is no problem.

    Can someone give me pointers in tracing this issue? Thanks!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Check your uploads path in Settings -> Media. Sounds like it's been changed.

  3. nsitu
    Member
    Posted 2 years ago #

    Upload path is 'wp-content/uploads'

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Try removing the path and leaving the uploads path blank.

  5. nsitu
    Member
    Posted 2 years ago #

    Okay, good suggestion. I just tried it, and it makes no difference. I don't think it's a problem with the path, but rather the attachment. I want the file to show up in the Gallery tab once it's inserted, and that's not happening right now.

  6. nsitu
    Member
    Posted 2 years ago #

    I decided to compare with another fresh WordPress install. The fresh copy does not have this issue.

    I discovered that the media library, when functioning properly, lists a hidden field with each item like this:
    <input type="hidden" name="attachments[10][post_parent]" id="attachments[10][post_parent]" value="163">

    This field is, for some reason, missing on the broken install.

    I also discovered that WordPress renders this hidden field in /wp-admin/includes/media.php, around line 1404:

    foreach ( $hidden_fields as $name => $value )
    		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
    
    	if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
    		$parent = (int) $_REQUEST['post_id'];
    		$parent_name = "attachments[$attachment_id][post_parent]";
    		$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
    	}
    
    	return $item;

    Still not sure where to go with this, though. Thanks for any further ideas.

  7. nsitu
    Member
    Posted 2 years ago #

    Okay, my bad: it looks like this behavior is by design. A file can only be attached to one post at a time. So, clicking "Insert into Post", does not guarantee that a file will necessarily attach. If it's already attached somewhere else, the existing attachment will hold.

    It makes me wonder if there's an easier way to manage attachments. Is there some plugin that adds an "Attach To" button when editing media?

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    Not that I'm aware of. As you've said, a file can only be attached to one post at a time. But you could upload a fresh copy of the file to the second/new post.

Topic Closed

This topic has been closed to new replies.

About this Topic