Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxyudin/80523f59b260f85d2f4aae33f6281905 to your computer and use it in GitHub Desktop.
Save maxyudin/80523f59b260f85d2f4aae33f6281905 to your computer and use it in GitHub Desktop.
[WordPress] Redefine get_terms() default arguments
// https://wordpress.stackexchange.com/questions/339849/how-to-list-categories-in-reverse-alphabetical-order/339853#339853
add_filter( 'get_terms_args', 'mxd_term_args', 10, 2 );
function mxd_term_args( $args, $taxonomies ) {
// don't affect admin area
if ( is_admin() ) {
return $args;
}
// redefine default arguments for 'category' taxonomy ONLY
if( in_array( 'category', $taxonomies )) {
$args['orderby'] = 'name';
$args['order'] = 'DESC';
$args['hide_empty'] = false;
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment