I am using wp_query to get uploaded medias. Everything is working fine, but wp_query will return the medias with no post attached. This is not what I wanted. How can I exclude the unattached media from the wp_query?
This is my query arguments look like:
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$attachemnt = new WP_Query($args);
Is there any argument that can use for exclude the unattached media in wp_query class?
Thanks
All media (somewhat incorrectly) in the
$wpdb->posts
table will be “attachments” whether actually attached or not. “Attachments” that are actually attached will have apost_parent
other than 0, so what you need are all of the attachments that have a 0 in thepost_parent
column, if I understand you.?>