Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 22, 2015 02:18
Show Gist options
  • Save robneu/6402258 to your computer and use it in GitHub Desktop.
Save robneu/6402258 to your computer and use it in GitHub Desktop.
Use pre_get_posts to change the ordering of category posts to the title.
<?php
add_action( 'pre_get_posts', 'prefix_change_category_order' );
/**
* Customize category Query using pre_get_posts.
*
* @author FAT Media <http://youneedfat.com>
* @copyright Copyright (c) 2013, FAT Media, LLC
* @license GPL-2.0+
* @todo Change prefix to theme or plugin prefix.
*
*/
function prefix_change_category_order( $query ) {
if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_category() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'DESC' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment