Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //get current
  3. $post_terms = get_the_terms($post->ID, 'the-creating-artists');
  4. if($post_terms){ //put everything inside this, makes sure that if there is no terms set we wont get just any posts
  5.     $slug_array = array();
  6.     foreach($post_terms as $single_term){
  7.         $slug_array[] = $single_term->term_id;
  8.     }
  9.     // args
  10.     $args = array(
  11.         'posts_per_page' => 3,
  12.         'post_type' => 'artists',
  13.         'orderby' => 'rand'
  14.         'tax_query' => array(
  15.             array(
  16.                 'taxonomy' => 'the-creating-artists',
  17.                 'field' => 'term_id',
  18.                 'terms' => $slug_array
  19.             )
  20.         )
  21.     );
  22.     // the query
  23.     $the_query = new WP_Query( $args );
  24.     if($the_query->have_posts()){
  25.         echo '<ul>';
  26.             while($the_query->have_posts){
  27.                 $the_query->the_post();
  28.                 echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
  29.             }
  30.             wp_reset_postdata();
  31.         echo '</ul>';
  32.     }else{
  33.         echo '<p>No related posts</p>';
  34.     }
  35. }else{
  36.     echo '<p>No related posts</p>';
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement