Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. $terms = wp_get_post_terms( $post->ID, 'artists' );
  3. if($terms){
  4. // post has course_type terms attached
  5. $artists = array();
  6. foreach ($terms as $term){
  7. $artists[] = $term->slug;
  8. }
  9.  
  10. $original_query = $wp_query;
  11. $wp_query = null;
  12. $wp_query = new WP_Query( array(
  13. 'post_type' => 'artwork',
  14. 'tax_query' => array(
  15. array(
  16. 'taxonomy' => 'artists',
  17. 'field' => 'slug',
  18. 'terms' => $artists, //the taxonomy terms I'd like to dynamically query
  19. 'posts_per_page' => '-1'
  20. ),
  21. ),
  22. 'orderby' => 'title',
  23. 'order' => 'ASC'
  24. ) );
  25.  
  26. $image = get_field('artwork_image');
  27. $size = 'artwork-small';
  28. $img = $image['sizes'][ $size ];
  29.  
  30. if ( have_posts() ): ?>
  31. <ul>
  32. <?php while (have_posts() ) : the_post(); ?>
  33. <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo $img ?>" alt="<?php echo $image['alt']; ?>" /><?php the_title(); ?></a></li>
  34. <?php endwhile; ?>
  35. </ul>
  36. <?php endif;
  37. $wp_query = null;
  38. $wp_query = $original_query;
  39. wp_reset_postdata();
  40. } // end if($terms)
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement