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 have a loop to show my custom post type of 'case_studies'. It originally showed all posts until I wanted to just show 3 specific posts. The problem is that it only shows the first post in my list of 'p=54,49,44'. What am I doing wrong?

$case_studies = new WP_Query();
                $count = 0; 
                while($case_studies->have_posts()) : $case_studies->the_post(); $count++;
                    $custom = get_post_custom($post->ID);
                    $case_studies_image_url = $custom['second_image'][0];
share|improve this question
p parameter is for single post selection(just a specific one), if you need a group use post__in as suggested by Steve. – t31os Feb 4 '11 at 12:14
up vote 3 down vote accepted

I think you need to change:



$case_studies->query_posts( array( 'post__in' => array( 54, 49, 44 ) ) );

I'd look at this page for LOTS more examples. http://codex.wordpress.org/Function_Reference/query_posts. when your there search for "Multiple Posts/Pages Handling".

Hope this helps, I'm still new to wordpress.

share|improve this answer
You should really use get_posts() instead of query_posts(). "The query_posts() function is intended to be used to modify the main page loop only. It is not intended as a means to create secondary loops on the page. If you want to create separate Loops outside of the main one, you should use get_posts() instead. Use of query_posts() on loops other than the main one can result in your main loop becoming incorrect and possibly displaying things that you were not expecting." (codex.wordpress.org/Function_Reference/…) – tnorthcutt Feb 4 '11 at 4:42
There is no WP_Query->query_posts() method, you are confusing it with query_posts() function. $case_studies->query() is correct. – Rarst Feb 4 '11 at 6:29
@Steve Fischer - Nice answer. – MikeSchinkel Feb 4 '11 at 6:36
@Rarst & @MikeSchinkel I appologize. I mis-typed. I think I meant $case_studies = query_posts(..... – Steve Fischer Feb 4 '11 at 14:12
@Steve Fischer your advice on post__in is accurate, but query_posts() is unfitting for secondary loop - WP_Query object as in question or get_posts() as per @tnorthcutt comment are appropriate. – Rarst Feb 4 '11 at 14:42

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.