Advertisement
vtxyzzy

Posts in order by id array

Jun 2nd, 2012
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. // Show posts in order of post__in array
  2. $id_array = array(589,39,981,531);
  3. $args = array(
  4.    'post__in' => $id_array,
  5.    'ignore_sticky_posts' => 1,  // Stickies will mess this up
  6. );
  7. query_posts($args);
  8. if (have_posts()) :
  9.    usort($wp_query->posts, function($a, $b) use ($id_array) {
  10.       return array_search($a->ID, $id_array) - array_search($b->ID, $id_array);
  11.    });
  12.    while (have_posts()) :
  13.       // Put your own loop code here
  14.       the_post();
  15.       echo "<p>ID: $post->ID</p>";
  16.    endwhile;
  17. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement