Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Created October 23, 2015 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc0ttkclark/d47d657fe05d40f00219 to your computer and use it in GitHub Desktop.
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}`
<?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