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 have the following:

<?php $num_cols = 2; // set the number of columns here


            $args = array(
                    'post_type' => 'testimonials',
                    'posts_per_page' => 4,
                    'orderby' => 'ID', 
                    'include' => '883, 563, 568, 106',                                  
                    'order' => ''           

                    ); 
            query_posts($args);
            if (have_posts()) :
            for ( $i=1 ; $i <= $num_cols; $i++ ) :
            echo '<div id="col-'.$i.'" class="col">';
            $counter = $num_cols + 1 - $i;
            while (have_posts()) : the_post();

            if( $counter%$num_cols == 0 ) : ?>
                <div id="box">

                <?php the_post_thumbnail('post-thumbnail', array('title' => '', 'alt' => '')); ?>



                <?php the_excerpt();?>
                </div>
                <?php endif; $counter++;
                  endwhile;
                  echo '</div>'; 
                  endfor;
                  endif; 
                wp_reset_query(); 
                ?>

I thought that simply putting the post Ids, I could have the specific posts appear, and only those posts. Unfortunately, that doesn't seem to be the case. So I was wondering if anyone knew how I can accomplish this.

Thanks in advance!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

use post__in:

$args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => 4,
    'orderby' => 'ID', 
    'post__in' => array(883, 563, 568, 106);
); 
share|improve this answer
    
Thank you Milo! I managed to get the specific posts to appear, but not in that specific order. –  Nina Sep 12 '11 at 19:03
    
@Nina - that's due to the way the underlying MySQL database engine works. the simplest way to get the order you want is to loop over your array of IDs, and for each ID, loop through the posts to find the matching result. your other option is more complex and requires directly modifying the SQL query to get MySQL to pull them in that specific order. –  Milo Sep 12 '11 at 19:10
$args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => 4,
    'orderby' => 'post__in', 
    'post__in' => array(883, 563, 568, 106);
); 

Using post__in within the orderby value it will honour the order of the array of IDs passed in post__in

share|improve this answer
    
Welcome to WPSE and the SE network, @stephenkeable! Exceptional formatting and a solid, concise answer. Keep up the good work ;) –  boscho May 2 '13 at 20:24

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.