WordPress: Sorting your Pages and Posts
If you have been using WordPress and updating content for a long time like us, you’ll find that you’ve got many hundreds of pages and posts on your site.
When, using the dashboard at the back-end you check on your pages and posts you will see them sorted into Alphabetical order by title.
Sure you can re-sort them by clicking on the date column twice, but this is an uneceesary step that can be quickly fixed with a few lines of code in your Theme folder.
Our assumption is that you’ve created a Child theme to tailor your site, but irrespective of that or not, the same applies to have your pages on posts sorted in a different order.
In the dashboard, using the Appearance -> Theme Editor option, you will be presented with an Edit Themes page.
Depending upon the theme used your page will look something like this:

On the right-hand side, you will see a section called Theme functions (underneath will identify the actual .php file, usually functions.php.
Clicking this will bring up the file in the online editor. By scrolling to the bottom and adding the following code, you can change the sort order of the All Pages and All Posts page to sort in Date order.
add_filter('pre_get_posts', 'my_set_post_order_in_admin' );
function my_set_post_order_in_admin( $wp_query ) {
global $pagenow;
if ( is_admin() && $_GET['post_type'] == 'page' && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
$wp_query->set( 'orderby', 'date' );
$wp_query->set( 'order', 'DESC' );
}
}
Entering this code at the foot of the file and clicking the Update File button and the sort will be you new default.
If you do not have the permissions to use the built-in WordPress theme editor, you will have to make the changes to the theme functions.php outside of WordPress using either your hosting provider’s file manager or via a file editor after connecting to your server via SSH or Telnet.
If you feel this may be a little too technical for you, you can always call us to provide support for you.
[forminator_form id=”77″]