Manual Sort Order for Authors or Users – WordPress

Sorting Cat. Get it? Like "Sorting Hat?" Any Harry Potter Fans out there?

Sometimes it’s necessary to manually select the order in which to sort your authors on your page listing all your authors or users. It is a little tricky to do, but I’ll break it down for you in this simple tutorial.

First, you are going to need to add a custom meta field for your users. There are many ways to do this that are not discussed here, though using Advanced Custom Fields is my favorite method, as the UI is all visual and requires no coding.

In this example, I created a custom meta field for authors named “order”. This is the field in which we are going to manually enter the order in which we want our authors to appear. In the user edit screen in the WordPress backend, setting our “order” value to ‘1’ should result in that author being listed first, with each subsequent number being listed after. I haven’t tested it to see if negative numbers would work, but I imagine they might!

Now to actually list the authors on our author results template. You need to have a separate template file for this. Typically to actually use it, you just create a page template and then select this template from the dropdown menu in the page edit screen.

The following code will query all the authors satisfying our parameters, and then sort them in our required order. I have a custom meta key which I use to specify which authors get listed, and it is simply a checkbox for the meta key named “display_author”. A meta value of “1” indicates that the box is checked and that other should be displayed. You could create this yourself, just like you created the “order” meta key if you wished. In my case, I have no other parameters, but you may want to add some, perhaps to specify that you only want “authors” as opposed to “subscribers” or any other role.

Now for the code. In this example, we are going to display the names of the authors with links to their profiles, a thumbnail, and a brief bio excerpt.

There you have it! This should be a good starting point to use for your own author page. Take a look at the comments to learn exactly how you can customize this.

One simple customization would to reverse the order of the authors which is actually quite simple. All you need to do is replace

with:

Simple! Let me know if you have any questions about this in the comments. Credit goes to ClarkLab for the idea and much of the original code, including the cmp function that actually does the sorting. As of 2017 the original post seems to be missing, but I’ll leave the link to his site up.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.