codebloo

Custom Taxes with posts

Feb 8th, 2017
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. $taxonomyName = 'types';
  3. $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'hide_empty' => true));
  4.  
  5. foreach($parent_terms as $parent_term ) {
  6. // display top level term name
  7. echo '<div class="archive_box"><header><h3>'. $parent_term->name . '</h3></header>';
  8. $child_terms = get_terms($taxonomyName, array('parent' => $parent_term->term_id, 'hide_empty' => true));
  9. foreach($child_terms as $child_term ) {
  10.  
  11.  
  12. // display name of all childs of the parent term
  13. echo '<div class="tax_section"><h3 class="tax_name">'. $child_term->name . '</h3>';
  14. echo '<ul class="archive_content">';
  15.  
  16. //Loop goes here
  17. // max 3 posts from each child term, post type 'archives'
  18.  
  19. $childposts = new WP_Query(
  20.  
  21. 'post_type' => 'archives',
  22. 'showposts' => 3,
  23. 'tax_query' => array(
  24. array(
  25. 'taxonomy' => 'types',
  26. 'field' => 'term_id',
  27. 'terms' => $child_term->term_id
  28. ),
  29. ),
  30. );
  31.  
  32. foreach($childposts as $cp):
  33. echo '<li><a href="'.get_permalink($cp->ID).'">'.$cp->post_title.' <i class="fa fa-arrow-circle-o-right" aria-hidden="true"></i></a></li>';
  34. endforeach;
  35.  
  36.  
  37. //end loop
  38. echo'</ul><a href="'. $child_term->slug .'" class="button">More '. $child_term->name .'</a></div>';
  39. }
  40. //end archivebox
  41. echo '</div>';
  42. } ?>
Advertisement
Add Comment
Please, Sign In to add comment