I have a list of post id's which I would like to loop the posts for, I have tried using the WP_QUERY with post__in, but this does not keep the order that the id's are listed in inside the $sorted array.
What is the simplest way of looping an array of id's as posts, but overriding the natural post order for the order that the $sorted array is listed?
$args = array (
'post__in' => $sorted, // array of id's that I want in order
'posts_per_page' => -1, // so that it shows everything in the array
'ignore_sticky_posts' => 1 // so that stickys dont affect order
);
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>n' . get_the_title() . ' - '. get_the_ID () .'</li>';
}
echo '</ul>';
} else {
_e( 'Sorry, no posts matched your criteria.' );
}
wp_reset_postdata();