Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get the post's terms (troubleshooting - can be removed once figured out!
- $category_terms = wp_get_object_terms($post->ID, 'category');
- if(!empty($category_terms)){
- if(!is_wp_error( $category_terms )){
- echo 'Terms <ul>';
- foreach($category_terms as $term){
- echo '<li><a href="'.get_term_link($term->slug, 'category').'">'.$term->name.'</a></li>';
- }
- echo '</ul>';
- }
- }
- //get post terms done
- // get the custom post type's taxonomy terms
- $custom_taxterms = wp_get_object_terms( $post->ID,
- 'category', array('fields' => 'ids') );
- // arguments
- $args = array(
- 'post_type' => 'program_listings',
- 'post_status' => 'publish',
- 'posts_per_page' => 5, // you may edit this number
- 'orderby' => 'rand',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'category',
- 'field' => 'id',
- 'terms' => $custom_taxterms
- )
- ),
- 'post__not_in' => array ($post->ID),
- );
- $related_items = new WP_Query( $args );
- // loop over query
- if ($related_items->have_posts()) :
- echo '<h2>Other Programs in this category</h2><ul>';
- while ( $related_items->have_posts() ) : $related_items->the_post();
- ?>
- <li style="margin-left:10px;list-style:none;"><a href="<?php the_permalink(); ?>"
- title="<?php the_title_attribute(); ?>">
- <?php the_title(); ?></a></li>
- <?php
- endwhile;
- echo '</ul>';
- endif;
- // Reset Post Data
- wp_reset_postdata();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement