How to display sorted posts in the ‘All Posts’ page

I’ve been following this tutorial to build a sorting page for my posts:
http://soulsizzle.com/jquery/create-an-ajax-sorter-for-wordpress-custom-post-types/

The sorting works fine, but the new sorting is not reflected back in the ‘All Posts’ section under ‘Posts’, it only displays sorted under the ‘Sort Posts’ submenu created by this code in the tutorial.

How would I extend this further to also sort the posts correctly under ‘All Posts’, as it is a bit confusing for the user as it is?

Also, does anybody know why there is no functionality for sorting, especially for pages and custom post types (I can imagine posts being more date-oriented), built into the WP Core?

1 Answer
1

I think this is what you want…

This isn’t tested so you may have to fiddle with it.

in your functions.php file, add something like this :


EDIT (2)

After rereading, I saw you’re not using custom post types, so i’ll change my code accordingly. I don’t know how to detect when you’re on the ‘manage all posts’ page, so maybe someone can complete my 'if' statement.

This should work.

 function set_post_order_in_admin( $wp_query ) {
      if ( is_admin() ) {
           if( 'edit.php' === $GLOBALS['pagenow'] ) { 
                $wp_query->set( 'orderby', 'menu_order' );
                $wp_query->set( 'order', 'ASC' );
           }
      }
 }
 add_filter( 'pre_get_posts', 'set_post_order_in_admin' );

Leave a Comment