Why Change the Order of WordPress Post?
By default, WordPress sorts your posts in reverse chronological order (newest to oldest). This is okay for most people, but there are situations when you might want to change the order. For instance, you might have an old post you want to move to the front of your blog, or you might want to push a less helpful post back further out of sight. If you are using WooCommerce you might want to move a product to the top of your shopping page.
Whatever your reasons are, WordPress has no built-in feature to help you accomplish this. It would be nice to see this implemented in the future, but for now you will need to use one of the three methods I have shown below.
Table of Contents
- Reorder Your Post by Changing the Date
- Reorder Your Post Using a Plugin
- Reorder Your Post With Custom Code
Method 1: Reorder Your Post by Changing the Date
In the image below, you can see that we have three different posts. “Example Post Three” is on top because it was the last post published. However, in this example, we want “Example Post One” to be on top. To do this we will need to change the publish date. Click on “Edit” under the post title in which you want to change.
On the right-hand side, there is a drop-down menu where you can select a new publish date. In this example, we will be choosing a date more recent than “Example Post Three”. Once you have selected a date, click the Update button.
Now that you have set an earlier published date on “Example Post One” it will be at the top of the list. This change will also be reflected on the frontend.
This is a fast way to change the order of your posts and works great if you only need to move a few around. If you need to do a lot at once, I recommend using one of the other methods below.
Method 2: Reorder Your Posts Using a Plugin
This is by far one of the easiest and best ways to change the order of your WordPress posts. There are several plugins out there, but I recommend “Post Types Order”. Post Types Order will allow you to reorder posts for any custom post types you have defined, including default Posts using a drag and drop interface.
It currently has over 3.2 million downloads and a near-perfect rating with over 200 reviews. Post Types Order can be downloaded from the WordPress Repository or from within your dashboard under “Add New” plugins.
After you have installed and activated the plugin, there will be a new option under the posts tab called Re-Order.
This will bring you to a page similar to the one shown below. Here you can drag and drop posts in whatever order you like.
It’s that easy! Post Types Order also has an advanced (paid) version that comes with hierarchically post types order, manual / automatic sorting, individual category order, conditionals to apply, paginations for large list, and a mobile ready interface.
Method 3: Reorder Your Post With Custom Code
Your last option of changing posts order would be to use some custom code. Below is an example of how you could sort your posts in ascending order on the front end.
function change_posts_order( $query ) {
if ( $query-is_home() && $query-is_main_query() ) {
$query-set( 'orderby', 'title' );
$query-set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', ' change_posts_order ' );
This code will need to be added to your themes functions.php file. It’s always best practice to create a child theme before editing your functions.php file. This will allow you to revert back if problems arise. You could also use code snippets, an easy way to add custom snippets to your theme’s functions.
Conclusion
Hopefully, you now have a better understanding of WordPress posts and how you can change their order if the need arises. Even though WordPress does not have a built-in post re-ordering feature, setting up your own solution is very easy. In this post, I have shared what I think are the three best ways to accomplish this.
If you enjoyed this tutorial, please be sure to follow us on Facebook and Twitter. You can also find us on Freelancer if you need some help with your WordPress website or web development issues.