Skip to content

Instantly share code, notes, and snippets.

@jdcauley
Created February 5, 2016 19:54
Show Gist options
  • Save jdcauley/cef9be91cd7be8f955c9 to your computer and use it in GitHub Desktop.
Save jdcauley/cef9be91cd7be8f955c9 to your computer and use it in GitHub Desktop.
ordering term checkboxes
function get_api_terms($term_id){
$posts = get_posts(array(
'post_type' => 'offer',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'offer_category',
'field' => 'term_id',
'terms' => $term_id,
)
)
));
$post_term_array = array();
foreach($posts as $post){
$post_terms = wp_get_post_terms( $post->ID, 'offer_trait');
foreach($post_terms as $post_term){
$post_term_array[] = $post_term->term_id;
}
}
$trait_terms = get_terms('offer_trait', array(
'orderby' => 'term_id'
));
$term_array = array();
foreach($trait_terms as $trait){
if(($trait->parent == 0) || in_array($trait->term_id, $post_term_array)){
$term_array[$trait->term_id] = $trait;
}
}
// if($data = get_transient('api_terms_' . $term_id)){
//
// return $data;
//
// } else {
//
// set_transient('api_terms_' . $term_id, $term_array, 3600);
// $data = $term_array;
// }
return $term_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment