Support MB User Meta Orderby and Sort Order on frontend for Post Checkbox List. Reply To: Orderby and Sort Order on frontend for Post Checkbox List.

#5210
Anh TranAnh Tran
Keymaster

The menu_order is used by WP_Query which has effect only when you use a custom query.

Because the rwmb_meta function only returns the values stored in the post meta, it doesn't use the WP_Query and thus doesn't have the menu_order affected. However, after you change the post order, IF you edit the post and save the post meta again, then the new values might have the new order affected.

In general, if you want to make sure it always work, you should use a custom query like this:

$posts_array = rwmb_meta( '_posts_select' );
$query = new WP_Query( array(
    'post_type' => 'post',
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'post__in' => $posts_array,
) );
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) : $query->the_post();
        // Do something
    endwhile;
}