how to sort post in admin column by recently

admin2025-06-03  3

i have created custom post type

my problem is:

in admin column, posts are sorted by ID

how can change it to date. In other words, i want to sort post by recently

i have created custom post type

my problem is:

in admin column, posts are sorted by ID

how can change it to date. In other words, i want to sort post by recently

Share Improve this question asked Mar 2, 2015 at 7:44 MohamadHosseinMohamadHossein 4351 gold badge5 silver badges15 bronze badges 5
  • I hope you do know that post ids are set to autoincrement and the oldest post will have the least id and so on. So unless you have some system that checks the missing post ids (of the ones deleted) and switches off Auto Increment and then adds new posts with old ids, the question doesn't stand. – Saurabh Shukla Commented Mar 2, 2015 at 11:06
  • 1 @Ehsan - Unless I'm losing the plot, posts are by default sorted by date when viewing them in the Admin area. If that is not what you want, most of the columns are sortable by clicking on the column header. – David Gard Commented Mar 2, 2015 at 16:51
  • @SaurabhShukla - Users can edit the publish date of a Post after it has been created, so if Posts were to be ordered by ID (which they are not by default) then they wouldn't necessarily be in date order. – David Gard Commented Mar 2, 2015 at 16:52
  • @DavidGard Oh, that I didn't consider in this context thanks to the description I have. – Saurabh Shukla Commented Mar 2, 2015 at 17:02
  • 2 @DavidGard tanks. my problem is that you told about this: "losing the plot, posts are by default sorted by date when viewing them in the Admin area" – MohamadHossein Commented Mar 3, 2015 at 5:14
Add a comment  | 

2 Answers 2

Reset to default 1

You must add this part to function.php:

add_action( 'pre_get_posts', 'example_func', 1 );
  function example_func( $query ) {
   if ( is_admin() && $query->is_main_query() ) {
     $query->set( 'order' , 'DESC' );
   }
   return $query;
}
add_action( 'pre_get_posts', 'change_post_sort', 1 );
function change_post_sort( $query ) {
        if ( is_admin() && $query->is_main_query() ) {
            $query->set( 'order' , 'DESC' );
            $query->set( 'orderby', 'modified');
    return $query;
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748945837a315050.html

最新回复(0)