Skip to content

Instantly share code, notes, and snippets.

@kovshenin
Created July 25, 2011 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovshenin/1103915 to your computer and use it in GitHub Desktop.
Save kovshenin/1103915 to your computer and use it in GitHub Desktop.
Default posts order by name in admin
<?php
/*
* This snippet overrides the default post ordering in the edit posts table (admin),
* while keeping other post ordering options (by clicking on the table headings)
* still available. Useful for CMS-like setups and could be tweaked for
* custom post types as well
*
* Konstantin Kovshenin
* http://theme.fm
*/
add_action( 'pre_get_posts', 'my_pre_get_posts', 10, 1 );
function my_pre_get_posts( $query ) {
if ( $query->is_admin && ! isset( $query->query_vars['orderby'] ) ) {
$query->set('orderby', 'title');
$query->set('order', 'asc');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment