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", "field" => "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" => "id", '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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.