I want to order a query result by the same order as the post id's array given. E.g. I have:
$arrayPostsIds = array(30,5,17,10);
and I want to get the posts in that order. So after trying this:
add_filter('posts_orderby', 'edit_posts_orderby');
function edit_posts_join_paged($join_paged_statement) {
global $arrayPostsIds_id;
$join_paged_statement = 'FIELD(ID,'.implode(',',$arrayPostsIds).')';
return $join_paged_statement;
}
and then I get the new result, which should match the above order:
$temp = $wp_query; // assign ordinal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query( array( 'post__in' => $arrayPostsIds, 'ignore_sticky_posts' => true, 'date_query' => $date_query ) );
but I'm getting the result ordered by ID, so it's not keeping the desired order. Am I forgetting anything?