Forums

Query to display attachments where post_parent is NOT null (2 posts)

  1. moikirsch
    Member
    Posted 1 year ago #

    Hi,

    I have the following code...

    $args = array(
    		'post_type' => 'attachment',
    		'numberposts' => 10,
    		'post_status' => null,
    		'post_parent' => null, // any parent
    		'post_mime_type' => 'image',
    		'orderby' => 'rand',
    		);
    	return get_posts($args);

    This code returns 10 random images. I would like to make it ignore the images that doesn't have a parent (which is equal to Zero on the database).

    Does anyone know how to do this?

    Is it possible to use something that would translate into 'post_parent' > 0

  2. moikirsch
    Member
    Posted 1 year ago #

    No one knows a solution? or do I have to create a custom SQL for this?

Topic Closed

This topic has been closed to new replies.

About this Topic