Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $terms = wp_get_object_terms($post->ID, 'product-vendor', array('orderby' => 'name', 'order' => 'ASC'));
- if(is_array($terms)) :
- if(isset($terms[0])) : ?>
- <h2>Other <?php echo $terms[0]->name; ?> Products</h2>
- <ul><?php
- $args = array(
- 'post_type' => 'products',
- 'posts_per_page'=> 5,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product-vendor',
- 'field' => 'slug',
- 'terms' => $terms[0]->name
- )));
- $related_posts = get_posts( $args );
- if($related_posts) : ?>
- <ul>
- <?php foreach($related_posts as $related_post) : ?>
- <li><a href="<?php echo get_permalink($related_post->ID); ?>"><?php echo $related_post->post_title; ?></a></li>
- <?php endforeach; ?>
- </ul>
- <a class="button" href="<?php echo get_term_link($terms[0]); ?>">View More <?php echo $terms[0]->name; ?> Products</a>
- <?php else: ?>
- <li>No other products.</li>
- <?php endif; ?>
- <?php endif; ?>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement