Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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

1 Answer

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

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

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
add comment

Your Answer

 
discard

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.