Advertisement
Guest User

Untitled

a guest
Mar 8th, 2012
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2. $terms = wp_get_post_terms( $post->ID, 'course_type' );
  3. if($terms){
  4. // post has course_type terms attached
  5. $course_terms = array();
  6. foreach ($terms as $term){
  7. $course_terms[] = $term->slug;
  8. }
  9.  
  10. $original_query = $wp_query;
  11. $wp_query = null;
  12. $wp_query = new WP_Query( array(
  13. 'post_type' => 'courses',
  14. 'tax_query' => array(
  15. array(
  16. 'taxonomy' => 'course_type',
  17. 'field' => 'slug',
  18. 'terms' => $course_terms, //the taxonomy terms I'd like to dynamically query
  19. 'posts_per_page' => '-1'
  20. ),
  21. ),
  22. 'orderby' => 'title',
  23. 'order' => 'ASC'
  24. ) );
  25.  
  26. if ( have_posts() ): ?>
  27. <ul>
  28. <?php while (have_posts() ) : the_post(); ?>
  29. <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
  30. <?php endwhile; ?>
  31. </ul>
  32. <?php endif;
  33. $wp_query = null;
  34. $wp_query = $original_query;
  35. wp_reset_postdata();
  36. } // end if($terms)
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement