0

I need to get any posts by an id list ($id_list), here is my codes

query_posts(array('posts_per_page'=>-1,
               'caller_get_posts'=>1,
               'post_type'=>'any',
               'post__in'=>$id_list)
           );

i got posts and pages by this query, but attachments don't get included, i found they are filtered by 'post_type=any' which actually doesn't include attachment.

How do i get them all without have to do an extra query?

1
  • 1
    Attachments don't have a publish status, which is default for the query.
    – t31os
    Commented Feb 25, 2011 at 12:50

1 Answer 1

1

'post_type'=>'any' should get you all types except revisions so you should get the attachments but if you don't try:

query_posts( array( 
               'posts_per_page' => -1,
               'ignore_stickies' => 1,
               'post_type'=> array( 'post', 'page', 'attachment' ),
               'post_status' => array( null ),
               'post__in'=> $id_list 
) );

Update

As t31os pointed out that:

Attachments don't have a publish status, which is default for the query

so i added to the query_posts array 'post_status' => null and that should fix your query

5
  • still no luck, i guess it is a bug
    – Edward
    Commented Feb 25, 2011 at 11:27
  • See my comment on your question.
    – t31os
    Commented Feb 25, 2011 at 12:50
  • @t31os @Edward , updated the code in the answer
    – Bainternet
    Commented Feb 25, 2011 at 14:11
  • @t31os @Bainternet, you are rock! All about 'post_status' and i can get all expected results now. Just a small issue, code should be 'post_status' => array(null), "null" is treated not set and wordpress will use the default value instead.
    – Edward
    Commented Feb 27, 2011 at 4:58
  • Note: 'post_status' => null cannot work since WP_Query checks this using empty() and reverts to defaults. But 'post_status' => array(null) might work depending on the SQL it creates, though it's a bit hackish.
    – Ciantic
    Commented Nov 27, 2013 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.