Advertisement
Guest User

Untitled

a guest
May 28th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. $args = array(
  3. 'order' => 'ASC',
  4. 'hide_empty' => true,
  5. 'cache_domain' => 'core'
  6. );
  7. $terms = get_terms('brand', $args);
  8. foreach ($terms as $item) {
  9. if ($item->count == 1) {
  10. $tax_query = '';
  11. $tax_query[] = array('taxonomy' => 'brand','field' => 'term_id','terms' => $item->term_id);
  12. $term_post = get_posts(array('post_type' => 'prod','tax_query' => $tax_query));
  13. if (!empty($term_post)) {
  14. $term_post_link = get_permalink($term_post[0]->ID);
  15. echo '<li><a href="'.$term_post_link.'">'.$item->name.'</a></li>';
  16. }
  17. } else {
  18. echo '<li>' . $item->name . '&nbsp;(' . $item->count . ')' . '</li>';
  19. }
  20. }
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement