Last active
January 4, 2016 16:39
-
-
Save crondeau/11295123 to your computer and use it in GitHub Desktop.
This snippet pulls posts from a CPT from a specific taxonomy terms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This snippet is useful for displaying content in a sidebar for example. If you have | |
* a CPT and a taxonomy, you may want to display all the posts from a specific taxonomy. | |
* The example below pulls posts from a shop CPT, set to "Eat Drink" taxonomy term. | |
*/ | |
<aside class="widget"> | |
<h3>Eat & Drink</h3> | |
<ul> | |
<?php | |
$loop = new WP_Query(array( | |
'post_type' => 'shop', // This is the name of your CPT | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'type', // This is the name of your taxonomy | |
'field' => 'slug', | |
'terms' => array( 'eat-drink' ), // This is your taxonomy term | |
) | |
), | |
'posts_per_page' => -1, | |
'order' => 'ASC', | |
'orderby' => 'title' | |
)); | |
?> | |
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?> | |
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> | |
<?php endwhile; wp_reset_postdata(); ?> | |
</ul> | |
<a href="<?php echo home_url(); ?>/shops/" class="button">All Shops</a> | |
</aside> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment