Advertisement
Guest User

taxquery

a guest
Apr 16th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  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.         'field' => '???',
  23.         'terms' => '???',
  24.     );
  25.     // the query
  26.     $the_query = new WP_Query( $args );
  27.     if($the_query->have_posts()){
  28.         echo '<ul>';
  29.             while($the_query->have_posts){
  30.                 $the_query->the_post();
  31.                 echo '<li><a href=".get_permalink().">'.get_the_title().'</a></li>';
  32.             }
  33.             wp_reset_postdata();
  34.         echo '</ul>';
  35.     }else{
  36.         echo '<p>No related posts</p>';
  37.     }
  38. }else{
  39.     echo '<p>No related posts</p>';
  40. }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement