admin-plugins author calendar category facebook post rss search twitter

TIDY REPO

The best and most reliable WordPress plugins

Post Types Order

Plugin Author: Nsp Code

Jay Hoffmann

April 11, 2014

Admin, Page

Out of the box, the way to sort items in WordPress is to effect the “Order” metadata parameter post by post, or set up a custom query. Post Types Order brings a drag and drop ordering interface to the WordPress admin, and makes it easy to sort posts and custom post types.

What’s It Do?

Post Types Order adds a new option to the Posts, and any custom post type, called “Re-Order.” The Re-order menu will show you a list of items how they are currently ordered on your site. Then, you can drag and drop the posts around to sort and order them however you want. This change will be reflected on the front-end of your site, as blog posts and custom post types queries will be edited, and will be listed in your new, custom order.

How’s It Work?

When you first install and activate the plugin, you’ll be directed to configure it first by going to Settings -> Post Types Order. There are just a few options. The first is to select which user roles have access to the re-order menu item. Select the minimum role (Contributor, Author, Editor, Administrator, etc.) a user logged in to your admin should be from the drop-down menu. Next up is a checkbox to turn off or on “Auto-sort.” What this basically means is whether or not you want the changes in ordering you made to be automatically reflected on the front-end of your site. Chances are, you are going to want to leave this checked. If, however, you want your homepage to have the default sort by post date, and another “Blog” page to have the custom order you created with Post Type Order, you will want to uncheck this box and use a custom query on the Blog page, which I’ll return to. For curious developers, this is achieved by using “pre_get_posts” for Auto-sort and an “orderby” parameter otherwise.

Post Types Order Admin Settings page

Only a few options to set

The last option is a checkbox for “Admin Sort” which specifies if you want order changes to be reflected in post listings on the back-end.

To start sorting posts, just click on Posts, or a custom post type -> Re-order. Note that this option won’t be available to post types that have the “hierarchical” parameter set to true. This means that you won’t be able to Re-order Pages, and you may not be able to re-order other post types set up by external plugins or themes.

The Re-order link will take you to the ordering page for that post type. Each post title will be listed out in a small box in a long list that contains every post in that post type. Simply drag the post title boxes around to change the order of them. Once you have an order that you think fits well, simply click the “Update” button and you’ll be all set. If you left the “Auto-sort” option checked, then you will see the changes reflected on the front-end of your site immediately. Just visit any page where blog posts are listed and you will see your brand new order. You will also see the changes reflected in Post Listings, for example “All Posts” in the admin.

Post Types Order plugin drag and drop interface

Drag and drop posts to sort them

If you unchecked the “Auto Sort” option, that means you probably only want to use the custom order in specific places. So, just open up the template file that you want to show your custom order on, and enter in the following code:

// Set up the Post Type to reflect your new order
$args = array(
              'orderby'   => 'menu_order',
              'order'     => 'ASC'
            );

$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
	while ( $the_query->have_posts() ) {
              // some code
	}
} else {
	// no posts found
}

// Restore original Post Data
wp_reset_postdata();

You may have other parameters that you want to pass into the WP_Query object, but the key is to set the “orderby” parameter to “menu_order” and the “order” parameter to “ASC.” This will make sure that the query reflects the custom order that you have set up. If you want to learn more about setting up a new Query on WordPress theme templates, visit the Codex.

Costs, Caveats, Etc.

Post Types Order is set up in a responsible and performant way, so you shouldn’t run into many problems with it. If you are having trouble though, visit the Support Forums for assistance from the plugin’s developers.

Resources

Download Post Types Order Now!

Did you like this post?

About this Plugin
Get the latest

Signup for our newsletter to get plugin tips, and see what's coming down the pipe.

Plugin Categories