WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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?

share|improve this question
Attachments don't have a publish status, which is default for the query. – t31os Feb 25 '11 at 12:50
up vote 1 down vote accepted

'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 
) );


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

share|improve this answer
still no luck, i guess it is a bug – Edward Feb 25 '11 at 11:27
See my comment on your question. – t31os Feb 25 '11 at 12:50
@t31os @Edward , updated the code in the answer – Bainternet Feb 25 '11 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 Feb 27 '11 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 Nov 27 '13 at 13:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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