Order posts in a $wp_query manually
Build a custom WordPress query and order the posts however you want them. Notice that this won't work properly if you page results, so it is only useful in very specific cases.
Btw, wrap everything into your class and get rid o the global var when you use this ;-)
<?php
global $posts;
$posts = array( 1, 2, 3, 4, 5 );
$args = array(
'post__in' => $posts,
'posts_per_page' => 5,
'caller_get_posts' => 1 // ignore sticky status
);
$my_query = new WP_Query( $args );
/**
* Order an array of objects by object property
*/
function orderby( $a, $b ) {
global $posts;
$apos = array_search( $a->ID, $posts );
$bpos = array_search( $b->ID, $posts );
return ( $apos < $bpos ) ? -1 : 1;
}
usort( $my_query->posts, "orderby" );
?>
Thanks in advance!