Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <?php
  2. //get all terms (e.g. categories or post tags), then display all posts in each term
  3. $taxonomy = 'post_tag';// e.g. post_tag, category
  4. $param_type = 'tag__in'; // e.g. tag__in, category__in
  5. $cat_id = get_the_category();
  6. $cat = $cat[0];
  7.  
  8. $term_args=array(
  9. 'orderby' => 'name',
  10. 'order' => 'ASC',
  11. 'cat' => $cat,
  12. );
  13. $terms = get_terms($taxonomy,$term_args);
  14. if ($terms) {
  15. foreach( $terms as $term ) {
  16. $args=array(
  17. "$param_type" => array($term->term_id),
  18. 'post_type' => 'post',
  19. 'post_status' => 'publish',
  20. 'posts_per_page' => -1,
  21. 'caller_get_posts'=> 1
  22. );
  23. $my_query = null;
  24. $my_query = new WP_Query($args);
  25. if( $my_query->have_posts() ) {
  26. echo 'List of Posts in '.$taxonomy .' '.$term->name;
  27. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  28. <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  29. <?php
  30. endwhile;
  31. }
  32. }
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement