In the back-office of my theme, the users can choose which posts to display in the front page, and they can also choose in which order the selected posts should appear.
I have tried like this:
$aPostsIDs = array(1,3,2); // Note the 3 should appear before the 2
query_posts(array('post_type' => 'page',
'post__in' => $aPostsIDs,
'order_by' => 'FIELD(ID, '.implode(',',$aPostsIDs).')'));
But as expected it doesn’t work. The right way to do it according to the codex is:
add_filter('posts_orderby', 'edit_posts_orderby');
function edit_posts_orderby($orderby_statement) {
global $aPostsIDs;
$orderby_statement="FIELD(ID, ".implode(',',$aPostsIDs).')';
return $orderby_statement;
}
But that still doesn’t work! The posts are ordered by ID (1, 2, 3) instead of the given order (1, 3, 2).
Where should I look?
Thanks