Have you ever tried to change the standard order of posts on your site’s blog page? By default, posts are ordered based on the date that each post is published, and there’s no built-in way to change the order in which posts appear.
If you do want to change the post order, you have three options: change the post publish date, write some code to sort posts using a parameter other than the date of publication, or find a plugin that will do the job for you.
Changing the publish date is not a viable option for many blogs. So, in this article, we’ll look at the second and third options on the list. First, I’ll show you how to build a custom plugin to implement a custom post order. Second, we’ll take a look at a two plugins available from the WordPress plugin directory that can be used to create a custom post order.
Prerequisite Knowledge
This post assumes a certain level of WordPress programming knowledge. If you’ve never created a simple plugin or a page template before, you will struggle to follow along. If you do struggle to follow along, the following posts will help you learn what you need to know to understand the material in this tutorial:
- Creating Custom Page Templates in WordPress
- How to Create a WordPress Plugin
- An In-Depth Guide to Conquering WP_Query
If you aren’t interested in building a custom plugin you can skip to the list of plugins available from the WordPress plugin directory that make the process a lot easier.
In addition, I’ve pulled all of the code in this tutorial into a GitHub repo. If you’d like to see what the finished product should look like, you can view and download all of the code from GitHub.
Build Your Own Custom Post Order Plugin
There are two major steps to take to implement a custom post order:
- Add a custom field to posts that can be used as a basis for sorting the posts.
- Implement the custom sort order by modifying the main WordPress loop or building a custom loop and adding it to a sidebar widget or custom page template.
Let’s start by adding a custom field to the WordPress post editing screen. However, before doing that you’ll need to fire up your WordPress development environment, create a new plugin folder, and create a plugin file in that folder. If you want to see what my plugin’s structure looks like, you can see the finished product at GitHub.
Set Up the Custom Field
While you could just use the Custom Fields meta box in the post edit screen to add custom meta data to each post, I prefer to add a custom meta box and field right to the backend. That way, you can’t accidentally assign meta data to the wrong field.
The first step in adding a custom meta box to the backend is to create the meta box and add it to the post edit screen.
.gist table { margin-bottom: 0; }
That bit of code, added to your plugin file will create the custom meta box. Here’s what the box will look like:

You’ll notices that the callback function in the bit of code above is 'jpen_custom_post_order'
. Let’s create that function next and add it to our plugin file. It will add a field to the meta box we just created.
.gist table { margin-bottom: 0; }
That bit of code starts by setting a nonce. Next, the code creates a variable called $current_pos
and assigns the value of the current post sort order to that variable. Next, two paragraph elements create the visible content of the meta box field and the current value is echoed into the field if a current value exists.
Finally, we need to store user input to the database. We can do that by adding this bit of code to our plugin:
.gist table { margin-bottom: 0; }
That code first checks to make sure that the nonce has been set and that the user has permission to make changes to the post. If everything checks out, the post meta data is updated with the new custom post order value.
Display the Custom Field in the Admin
In the last section we added a custom meta box to the post edit screen and programmed it to store a numeric value. A little later we’ll use that numeric value to create a custom post order. However, before we get to that, we have another problem to solve.
As things stand, to see the current post sort order value we have to open each post and take a look at the custom meta box we just added to the post edit screen. That isn’t very convenient. Let’s add the custom sort order value to the admin post list so that we can quickly see the current post order value assigned to each post.
First, we need to add a custom column to the post list in the admin area. We can do that by adding this bit of code to our plugin:
.gist table { margin-bottom: 0; }
Next, we need to pull up the custom post order value for each post and list it in the new column. That’s not too difficult, and we can do it by adding this function to our plugin file:
.gist table { margin-bottom: 0; }
Great. Now, when we visit the blog post list in the admin we can easily see which posts have been assigned a custom sort order value.
Here’s how things are looking when we view the blog post list in the admin area:

Put the Custom Post Order to Good Use
Now that we’ve made it possible to assign a custom order to posts, it’s time to put that custom order to good use. However, before we can do that we’ll have to answer this question: “How do we want to use the custom sort order?”
There are several different ways you might want to implement the custom sort. Here are a few ideas:
- Sort all of your posts into a custom order and display the custom sorted list on your blog posts page. You probably wouldn’t want to do this on a busy blog, but if you use WordPress to host a series of instructional posts that and don’t add new posts frequently, this could be a valuable way to sort posts in any order.
- Create a curated list of posts and display them in the order of your choice using a custom page template. For example, you could curate the list to only include posts that also belong to a specific category and then sort them into whatever order you wish.
- Create a blog post list that begins with a few custom sorted posts and then includes all of the rest of your posts in their standard order.
Really, the sky is the limit. If you can think up a use for the custom sort order, and can figure out how to implement your idea, then it’s a viable idea. Let’s quickly walk through the three ideas above so you can see how each would be accomplished.
Replace Posts on the Blog Page with a Custom Sorted List
The easiest way to use the custom sort order is to replace the standard list of posts on your site’s blog page with the custom sorted list of posts. To do that, all you need to do is drop the following function into your plugin:
.gist table { margin-bottom: 0; }
Keep in mind that this function will only turn up posts that have been assigned a custom sort order value. Any posts that haven’t been assigned a custom sort order value will not be displayed on your blog page. In other words, if you do this, you’re going to have to assign a custom sort order value to every post that you want to see displayed.