$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>how to sort post in admin column by recently|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

how to sort post in admin column by recently

matteradmin8PV0评论

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;
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far