23

I have a special case where I'd like to order posts in a custom order and it would be great to use the "menu_order" field that is normally only used for pages. What would be the best way to expose that in the WordPress admin UI?

35

Apparently it's as easy as:

add_action( 'admin_init', 'posts_order_wpse_91866' );

function posts_order_wpse_91866() 
{
    add_post_type_support( 'post', 'page-attributes' );
}

And then doing the query:

$order_posts = new WP_Query(array(
    'post_type' => 'post', 
    'post_status' => 'publish', 
    'orderby' => 'menu_order', 
    'order' => 'ASC', 
) );
  • Glad I asked. I was thinking I'd need to add a custom meta box and just save to the posts table manually. – tooshel Mar 25 '13 at 16:57
  • Apparently, this doesn't work with Gutenberg. Here is an updated version that works: gist.github.com/chrisguitarguy/1301501 – yobddigi Mar 6 at 0:17
  • hooking into "admin_init" worked for me – Svetoslav Marinov Jul 5 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.