Wordpress: Enabling Page attributes for posts (sort_order)
I've often come across the need to sort blog posts by manualy setting the order and not ordering them by name or date, by default WordPress posts do not support the page attributes like pages: ( see image right )Using the native WordPress function "add_post_type_support( $post_type, $supports )", set the post type to "post" and support to "page-attributes", see example below.So to overcome this you can attach a very simple custom function to a hook in your functions.php file to add support for this feature. see: https://codex.wordpress.org/Function_Reference/add_post_type_support
In addition to this, using the Simple Page Ordering plugin, that allows you to drag and drop posts, pages and custom post types to set the menu_order attribute.
Add the following code snippet to your functions file:
add_action( 'admin_init', 'posts_order' );function posts_order(){add_post_type_support( 'post', 'page-attributes' );}
This will now enable you to use the "menu_order" option in your post query, like so :
array('orderby' => 'menu_order','order' => 'ASC');
So your query will look something like this, example:
$order_posts = new WP_Query(array('post_type' => 'post','post_status' => 'publish','orderby' => 'menu_order','order' => 'ASC',) );