• Resolved fvila789

    (@fvilawp)


    Uploaded images don’t appear in get_posts, although I can see them in Media > uploaded to this page.

    Here’s the code I’m using to loop:

    global $post;
    	if ( $images = get_posts(array(
    			'post_parent' => $post->ID,
    			'post_type' => 'attachment',
    			'numberposts' => -1,
    			'post_mime_type' => 'image',)))
    		{
    		foreach( $images as $image ) {

    The strangest thing is that it works on my localhost / Xampp site, but not on my production site. I tried removing bits, like the post_mime_type, but the only thing that retrieves anything is if I remove the ‘post_parent’ => $post->ID (I printed the $post->ID, it is available).
    Post is published and visibility is public.

    https://wordpress.org/plugins/frontend-uploader/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter fvila789

    (@fvilawp)

    Also when I look into phpmyadmin I can see the attachments:
    SELECT * FROM wp_posts WHERE post_parent=”11371″
    returns a whole list, and
    SELECT * FROM wp_posts WHERE ID=”11371″
    is my post

    Thread Starter fvila789

    (@fvilawp)

    Found it: image attachments were marked as private. I changed the code to

    global $post;
    	$a = get_posts(array (	 'post_parent' => $post->ID,
    			'post_type' => 'attachment',
    			'numberposts' => -1,
    			'post_mime_type' => 'image/jpeg',
    			 'post_status' => 'private' ));
    
    	if ( $images = $a)

    and it works. I don’t know whether there’s any problem with leaving the attachments private, the users have a simplified front-end interface and don’t need to go into the WP admin pages.

    Plugin Author Rinat

    (@rinatkhaziev)

    The idea behind attachments being private is that you have to approve them first, then their status is set to “publish”

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘uploaded images don't appear in get_posts’ is closed to new replies.