Using ‘post_parent’ only works sometimes for attachments

I need to get all attachments with a specific post parent. To do this I used the following code:

//this doesnt work
$attachmentsids = get_posts(array(“posts_per_page” => -1, “post_type” => “attachment”, “post_status” => “any”, “fields” => “ids”, ‘meta_key’ => ‘cf_attachment_approved’, ‘meta_value’ => false, ‘author’ => 1, ‘post_parent’ => 9440));

//this works
$attachmentsids = get_posts(array(“posts_per_page” => -1, “post_type” => “attachment”, “post_status” => “any”, “fields” => “ids”, ‘meta_key’ => ‘cf_attachment_approved’, ‘meta_value’ => false, ‘author’ => 1));

get_posts with ‘post_parent’ doesnt work, the one without works. I am 100% sure the post_parent id is correct.

Read more here:: Using ‘post_parent’ only works sometimes for attachments

Leave a Reply

Your email address will not be published. Required fields are marked *