How to Change Order or Posts or Custom Post Types in the Dashboard

If you purchase through a link on our site, we may earn a commission. Learn more.

In the WordPress dashboard, posts are displayed in the 'latest first' order. This also applies to pages and custom post types. However it is also easy to change this order if you wish to do so. It might be more practical for example, to have them display according to their title, in ascending order.
Table of Contents
WP Engine High Performance Hosting
BionicWP Hosting

In the WordPress dashboard, posts are displayed in the ‘latest first’ order. This also applies to pages and custom post types. However it is also easy to change this order if you wish to do so. It might be more practical for example, to have them display according to their title, in ascending order.

This is how you do it, using the pre_get_posts filter:

[php]
add_action( ‘pre_get_posts’, ‘mycpt_order’ );
/**
* Change order of custom post type to alphabetical ascending
*/
function mycpt_order( $query ) {
// check if we’re in admin, if not exit
if ( ! is_admin ) {
return;
}

$post_type = $query->get(‘post_type’);

if ( $post_type == ‘mycpt’ ) {
/* Post Column: e.g. title */
if ( $query->get( ‘orderby’ ) == ” ) {
$query->set( ‘orderby’, ‘title’ );
}
/* Post Order: ASC / DESC */
if( $query->get( ‘order’ ) == ” ){
$query->set( ‘order’, ‘ASC’ );
}
}
}

[/php]

Of course, replace mycpt with the name of your post type.

If you enjoyed this post, make sure to subscribe to WP Mayor’s RSS feed.

 

Jean Galea

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Discover more from our archives ↓

Popular articles ↓

5 Responses

  1. Wow. Interesting. Thanks.

    Question: Can this be used to sort by a post metadata field / value?

    If so, can you add that example above?

  2. Yes there is an easy way, if you don’t mind pasting some code into your functions.php file, or creating a simple plugin that does this.

    The WordPress query has many parameters, and one of them controls the order in which posts are displayed, as indicated above. You need to take a look at this link:

    Basically you will need to set the orderby to ‘date’ and order to ‘DESC’.

    1. Hmm! I understand most of those words. I’ll take a look at the link! Can I come back when I don’t understand it?? 😉

      Thanks for your help!

      1. HEEEEEEEELP! I’m WAY out of my depth here! Where do I find the functions.php file? Do I have to upgrade from .com?

  3. Is there an easy way to display posts from first to last, rather than the last up front? I ask because pleasepresshere.wordpress.com basically turned into a sort-of book, and it struck me that WordPress might further the e-book cause by adding such a feature.

    Thanks,

    3

Share Your Thoughts

Your email address will not be published. Required fields are marked *

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.