Support » Fixing WordPress » Get all images from published posts

  • Hello, I’m using get_children to retrieve all images from my site like

    $images = get_children( 'post_type=attachment&post_mime_type=image&numberposts=-1&order=ASC&orderby=menu_order&post_parent=' )

    This returns ALL images, not just published ones. I’m not 100% sure what is happening but it states here get_children sets the post_status param to ‘inherit’ as it presumes to be used with a defined parent, however I don’t want to define a parent, just get all images are from published posts.

    Any idea how to do that? Seems like a simple task.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m having the same trouble, i tried:

    $images =& get_children( ‘post_type=attachment&post_mime_type=image&post_status=publish’ );

    but setting post_status=publish returns nothing, going to turn on error reporting.

    Same issue pulling audio:

    $audios =& get_children( 'post_type=attachment&post_mime_type=audio/mpeg&post_parent=null' );

    Works, but

    $audios =& get_children( 'post_type=attachment&post_mime_type=audio/mpeg&post_parent=null&post_status=publish');

    returns nothing 🙁

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get all images from published posts’ is closed to new replies.