Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Forked from billerickson/gist:1612826
Created January 14, 2012 21:20
Show Gist options
  • Save GaryJones/1612938 to your computer and use it in GitHub Desktop.
Save GaryJones/1612938 to your computer and use it in GitHub Desktop.
Sort specific category to display alphabetically.
<?php
add_action( 'pre_get_posts', 'be_sort_articles_category' );
/**
* Sort 'articles' category by name
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function be_sort_articles_category( $query ) {
if( $query->is_main_query() && $query->is_category( 'articles' ) ) {
$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