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 problem with my code, I want to display 3 specific pages on my homepage but my code is not working.. here's the code..

<?php $args = array(
                      'post_type' => 'page',
                      'post__in' => array(3,5,7)
                    while (have_posts()) : the_post();
                    $do_not_duplicate = $post->ID; ?>
                <div class ="date_author group">
                    <h3 class="date"><?php the_time('M j, y');?></h3>
                    <h3 class="title"><a STYLE="text-decoration:none" href = "<?php the_permalink();?>"><?php           the_title();?></a></h3>

                    <?php the_excerpt();?>

                    <?php endwhile; ?>
share|improve this question
Not working is not a useful description. What happens instead? What debug data did you collect? Read How to ask a good question. – toscho May 8 '12 at 0:27
I'm sorry, The code displays nothing.. I'm sure that I have pages ID 3, 5, and 7 but it displays nothing. – markyeoj May 8 '12 at 0:32
Use get_posts() and enable the debug mode. – toscho May 8 '12 at 0:35
Thank you, you give me another idea on retrieving a post,, Im just a newbie in wordpress and it really helps but.. – markyeoj May 8 '12 at 2:39
up vote 1 down vote accepted

This is an inappropriate use of query_posts() which is only for modifying the main query for the page. Additionally, even if you change your snippet to use get_posts(), your template tags (e.g. the_excerpt()) won't work as get_posts() isn't a method of looping through posts, it just returns an array of posts.

What you want is WP_Query. Change your first lines of code to this:

$args = array(
    'post_type' => 'page',
    'post__in' => array(3,5,7)
$my_three_posts = new WP_Query( $args );
while ($my_three_posts -> have_posts()) : $my_three_posts -> the_post();
share|improve this answer
Thank you! it works like a luck :) – markyeoj May 8 '12 at 2:37

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.