Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.   $id_array = array(589,98,1021,531);
  3.   $args = array(
  4.      'post__in' => $id_array,
  5.      'caller_get_posts' => 1,  // stickies will mess this up
  6.   );
  7.   query_posts($args);
  8.   if (have_posts()) {
  9.      $id_ndx = array();
  10.      $orig_posts = $wp_query->posts;
  11.      // Create an array of IDs and their index number.
  12.      for ($i=0;$i < sizeof($orig_posts) ;++$i ) {
  13.         $id_ndx[$orig_posts[$i]->ID] = $i;
  14.      }
  15.      $wp_query->posts = array();
  16.      // Rebuild the $wp_query->posts array in the order of $id_array
  17.      foreach ($id_array as $id) {
  18.         if (isset($id_ndx[$id])) $wp_query->posts[] = $orig_posts[$id_ndx[$id]];
  19.      }
  20.      while (have_posts()) {
  21.         the_post();
  22.         echo "<p>ID: $post->ID</p>";
  23.      }
  24.   }
  25. ?>