
Untitled
By: a guest on
Jun 2nd, 2012 | syntax:
None | size: 0.75 KB | hits: 38 | expires: Never
<?php
$id_array = array(589,98,1021,531);
$args = array(
'post__in' => $id_array,
'caller_get_posts' => 1, // stickies will mess this up
);
query_posts($args);
if (have_posts()) {
$id_ndx = array();
$orig_posts = $wp_query->posts;
// Create an array of IDs and their index number.
for ($i=0;$i < sizeof($orig_posts) ;++$i ) {
$id_ndx[$orig_posts[$i]->ID] = $i;
}
$wp_query->posts = array();
// Rebuild the $wp_query->posts array in the order of $id_array
foreach ($id_array as $id) {
if (isset($id_ndx[$id])) $wp_query->posts[] = $orig_posts[$id_ndx[$id]];
}
while (have_posts()) {
the_post();
echo "<p>ID: $post->ID</p>";
}
}
?>