Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $args = array(
- 'order' => 'ASC',
- 'hide_empty' => true,
- 'cache_domain' => 'core'
- );
- $terms = get_terms('brand', $args);
- foreach ($terms as $item) {
- if ($item->count == 1) {
- $tax_query = '';
- $tax_query[] = array('taxonomy' => 'brand','field' => 'term_id','terms' => $item->term_id);
- $term_post = get_posts(array('post_type' => 'prod','tax_query' => $tax_query));
- if (!empty($term_post)) {
- $term_post_link = get_permalink($term_post[0]->ID);
- echo '<li><a href="'.$term_post_link.'">'.$item->name.'</a></li>';
- }
- } else {
- echo '<li>' . $item->name . ' (' . $item->count . ')' . '</li>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement