WordPress.org

Ready to get started?Download WordPress

Forums

Get all images from published posts (3 posts)

  1. mothmenace
    Member
    Posted 4 years ago #

    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.

  2. Zane Matthew
    Member
    Posted 3 years ago #

    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.

  3. longtailrider
    Member
    Posted 3 years ago #

    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 :(

Topic Closed

This topic has been closed to new replies.

About this Topic