WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Media LIbrary : Attached (5 posts)

  1. awx2d
    Member
    Posted 5 years ago #

    I'm using the following custom function to pull the first image out of all posts to display them in a gallery using timthumb.php to scale them;

    // Echo out Full Gallery
    function full_gallery() {
    	global $wpdb;
    	global $post;
    	$image = "";
    	$first_image = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type = 'attachment' ORDER BY <code>post_date</code> ASC LIMIT 0,1");
    	if ($first_image) {
    	$image = urldecode($first_image[0]->guid);
    	echo $image;
    	}
    }

    The problem I am having is that every image that is added either by using the Media Library or via the post using "Insert into post" is not getting attached to the post ..

    The image is in the post and visible but the when I check the media library it shows the image as unattached, the result is that the function above cannot fine the image as it is not attached to the post in the database

  2. metabaron
    Member
    Posted 4 years ago #

    Same here using the latest version of WordPress mu (2.8.4a)

  3. metabaron
    Member
    Posted 4 years ago #

    Ok, got it:
    in wp_xxx_posts, the value post_parent is not update when you create a new post and insert directly a new image.

    If you add an image, create a new post and insert this image (from the library), this works ...

    Someone to write a bug report? it's late here in France

  4. Creative Slice
    Member
    Posted 4 years ago #

    We've been having the same issue and have found this to definitely be a WordPress bug.

    The solution (until a fix is implemented) is to create pages (or posts) first and THEN go back into them and add the images.

    - Tim

  5. awx2d
    Member
    Posted 4 years ago #

    Solution is actually to ensure you enter a title for the post/page then select the main post area, then add your images. Works everytime!

Topic Closed

This topic has been closed to new replies.

About this Topic