Skip to content

Instantly share code, notes, and snippets.

@blainerobison
Created January 30, 2015 14:30
Show Gist options
  • Save blainerobison/16220392bdd29d8ee634 to your computer and use it in GitHub Desktop.
Save blainerobison/16220392bdd29d8ee634 to your computer and use it in GitHub Desktop.
wp: Order get_terms() Numerically [WordPress]
/**
* Order get_terms() by number
*
* @param string $orderby ORDERBY clause of the terms query.
* @param array $args An array of terms query arguments.
* @param string|array $taxonomies A taxonomy or array of taxonomies.
* @return string
*/
function prefix_get_terms_orderby_numeric( $orderby, $args, $taxonomies ) {
// cast term name as number
if ( in_array( 'numeric', $args ) )
$orderby = 't.name * 1';
return $orderby;
}
add_filter( 'get_terms_orderby', 'prefix_get_terms_orderby_numeric', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment