Skip to content

Instantly share code, notes, and snippets.

@avenirer
Last active February 14, 2019 12:58
Show Gist options
  • Save avenirer/bfeb10fcc509a13974c053e232338e3d to your computer and use it in GitHub Desktop.
Save avenirer/bfeb10fcc509a13974c053e232338e3d to your computer and use it in GitHub Desktop.
WordPress - get most used taxonomies
<?php
function getMostUsedTaxonomies($taxonomy, $fields = 'all', $orderBy = 'count', $orderDirection = 'desc', $limit = '30') {
$transientName = 'mostUsedTaxonomies_'.$taxonomy.'_'.$fields.'_'.$orderBy.'_'.$orderDirection.'_'.$limit;
$mainTechnologies = get_transient( $transientName );
if ( $mainTechnologies === false ) {
$params = array(
'taxonomy' => $taxonomy,
'hide_empty' => true,
'orderby' => $orderBy,
'order' => $orderDirection,
'number' => $limit,
'fields' => $fields
);
$mainTechnologies = get_terms($params);
set_transient($transientName, $mainTechnologies, 60*60*24);
}
return $mainTechnologies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment