Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement