Created
October 23, 2015 16:30
-
-
Save sc0ttkclark/d47d657fe05d40f00219 to your computer and use it in GitHub Desktop.
Example PHP of how to enable sorting by term name. `orderby=term_name` and `orderby_tax={taxonomy_name}`
This file contains 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 | |
/** | |
* Filter EP args to add support for orderby term_name | |
* | |
* @param array $formatted_args | |
* @param array $args | |
*/ | |
function ep_add_term_name_sort_support( $formatted_args, $args ) { | |
// Handle meta_value / meta_value_num sort | |
if ( ! empty( $args['orderby_tax'] ) && 'term_name' === $args['orderby'] ) { | |
$order = 'desc'; | |
if ( ! empty( $args['order'] ) ) { | |
$order = strtolower( $args['order'] ); | |
} | |
$formatted_args['sort'] = array( | |
array( | |
'terms.' . $args['orderby_tax'] . '.name' => array( | |
'order' => $order, | |
), | |
), | |
); | |
} | |
return $formatted_args; | |
} | |
add_filter( 'ep_formatted_args', 'ep_add_term_name_sort_support', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment