Created
January 2, 2012 08:27
-
-
Save wpfan/1549864 to your computer and use it in GitHub Desktop.
Order posts alphabetically using the pre_get_posts hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('pre_get_posts', 'blog_change_sort'); | |
function blog_change_sort( $query ) { | |
// Only modify main query | |
// On the tutorial category page | |
if( $query->is_main_query() && is_category('tutorials') ) { | |
$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