Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //get current
- $post_terms = get_the_terms($post->ID, 'the-creating-artists');
- if($post_terms){ //put everything inside this, makes sure that if there is no terms set we wont get just any posts
- $slug_array = array();
- foreach($post_terms as $single_term){
- $slug_array[] = $single_term->term_id;
- }
- // args
- $args = array(
- 'posts_per_page' => 3,
- 'post_type' => 'artists',
- 'orderby' => 'rand'
- 'tax_query' => array(
- array(
- 'taxonomy' => 'the-creating-artists',
- 'field' => 'term_id',
- 'terms' => $slug_array
- )
- )
- 'field' => '???',
- 'terms' => '???',
- );
- // the query
- $the_query = new WP_Query( $args );
- if($the_query->have_posts()){
- echo '<ul>';
- while($the_query->have_posts){
- $the_query->the_post();
- echo '<li><a href=".get_permalink().">'.get_the_title().'</a></li>';
- }
- wp_reset_postdata();
- echo '</ul>';
- }else{
- echo '<p>No related posts</p>';
- }
- }else{
- echo '<p>No related posts</p>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement