Reordering the way you want is really pretty trivial. Proof of concept:
$p = array(1,2,3);
var_dump($p);
array_push($p,array_shift($p));
var_dump($p);
With the WordPress code:
$p = get_posts('posts_per_page=3');
array_push($p,array_shift($p));
var_dump($p);
To make it more interesting, you can do the same with a filter. Since get_posts()
uses wp_query()
you can use the post_results
hook to reorder the results.
function post_shift_wpse_166761($p) {
remove_filter('posts_results','post_shift_wpse_166761');
array_push($p,array_shift($p));
return $p;
}
add_filter('posts_results','post_shift_wpse_166761');
$p = get_posts(
array(
'suppress_filters' => false,
'posts_per_page' => 3
)
);
var_dump(wp_list_pluck($p,'ID'));
Note that you also have to pass a suppress_filters
argument to get_posts()
.