Advertisement
Guest User

CPT display only related

a guest
Jul 31st, 2013
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- other posts -->
  2. <?php
  3. //get the post's terms (troubleshooting - can be removed once figured out!
  4. $category_terms = wp_get_object_terms($post->ID, 'category');
  5. if(!empty($category_terms)){
  6. if(!is_wp_error( $category_terms )){
  7. echo 'Terms <ul>';
  8. foreach($category_terms as $term){
  9. echo '<li><a href="'.get_term_link($term->slug, 'category').'">'.$term->name.'</a></li>';
  10. }
  11. echo '</ul>';
  12. }
  13. } //get post terms done
  14. ?>
  15. <?php
  16. //for a given post type, return all
  17. $category_terms = wp_get_object_terms($post->ID, 'category');
  18. $post_type = 'program_listings';
  19. $tax = 'category';
  20. $tax_terms = wp_get_object_terms($post->ID, 'category');
  21. if ($tax_terms) {
  22. foreach ($tax_terms as $tax_term) {
  23. $args=array(
  24. 'post_type' => $post_type,
  25. "$tax" => $tax_term->slug,
  26. 'post_status' => 'publish',
  27. 'operator' => 'AND',
  28. 'posts_per_page' => 5,
  29. 'caller_get_posts'=> 1
  30.  
  31. );
  32.  
  33. $my_query = null;
  34. $my_query = new WP_Query($args);
  35. if( $my_query->have_posts() ) {
  36. echo '<h2>Other programs in the '. $tax_term->name. ' category</h2> ';
  37. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  38. <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  39. <?php
  40. endwhile;
  41. }
  42. wp_reset_query();
  43. }
  44. }
  45.  
  46. ?>
  47.  
  48. <!-- end other posts -->
Advertisement
RAW Paste Data Copied
Advertisement