How To Reorder Standard & Custom Post Type Posts In WordPress

How To Reorder Standard & Custom Post Type Posts In WordPress

Ever since I started developing WordPress 3+ themes and using custom post types for things such as portfolios, services, faqs, staff, sliders..etc, I’ve been getting a lot of questions from people asking me how they can rearrange the order of their published posts. Unfortunately it’s not very obvious how to do this in WordPress and there isn’t a very easy and manageable way.

In the following post I’ll show you how you can e-order your custom posts using two different methods: changing the post date of your custom post or using a super awesome free WordPress plugin called “Post Type Order”.

Method 1: Change Post Date

The first method of changing your posts order is by changing the published dates of your posts. Most the time themes will use the default order_by => date argument in their themes so custom posts will show up in the order in which they were published.

note: May not work with all themes.

Step 1: Click on the quick edit button in the post editor

WordPress Quick Edit

Step 2: Change Post Date

Look at the dates of your published posts and you can change them to reorder them.

Method 2: Using The Post Type Order Plugin

My favorite way of changing the order of your posts is by using the “Post Type Order Plugin”. This plugin will allow you to easily move your posts around in a drag-and-drop fashion. In the video below you can see how epic this plugin is and how to use it to reorder your custom post type posts.

Plugin Page

Method 3: Using the pre_get_posts Filter

If you want to re-order your items via code its also very easy and you’ll want to use the pre_get_posts action in WordPress to do so. Please click on the former link to learn all about it. If you rather learn from an example, please have a look below!

function wpex_order_category( $query ) {
	// exit out if it's the admin or it isn't the main query
	if ( is_admin() || ! $query->is_main_query() ) {
		return;
	}
	// order category archives by title in ascending order
	if ( is_category() ) {
		$query->set( 'order' , 'asc' );
		$query->set( 'orderby', 'title');
		return;
	}
}
add_action( 'pre_get_posts', 'wpex_order_category', 1 );
AJ Clarke
Hey. My name is AJ and I am the boss around here. I own and operate WPExplorer. A website dedicated to everything I love about WordPress.
AJ Clarke
This article has 8 comments
    1. AJ Clarke says:

      I don’t really understand the question…What theme? What are you trying to do?

      Admin
  1. mafudim says:

    Hi! How to do the same with categories? Is it possible to rotate it in the theme Office Responsive Business Theme

  2. mafudim says:

    Found Plugin Category Order and Taxonomy Terms Order. I think this is the answer to my question

  3. Alex says:

    Thank you so much!!! I’ve been looking for a solution for that for ages, and you gave a quick and simple answer, AWESOME!

  4. Mayeenul Islam says:

    `Method 3: Using the pre_get_posts Filter` – can I integrate custom fields there?

Leave a Reply