Skip to content

Instantly share code, notes, and snippets.

@damianwajer
Last active August 29, 2015 14:08
Show Gist options
  • Save damianwajer/01df307da66db6ed8bad to your computer and use it in GitHub Desktop.
Save damianwajer/01df307da66db6ed8bad to your computer and use it in GitHub Desktop.
[WordPress] Taxonomy template
<?php
/**
* Taxonomy template
* @link http://codex.wordpress.org/Class_Reference/WP_Query
*/
// Protect against arbitrary paged values
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$taxonomy = get_query_var( 'taxonomy' );
$term = get_query_var( 'term' );
// The Query
$the_query = new WP_Query( array(
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term,
),
),
'posts_per_page' => get_option( 'posts_per_page' ),
'paged' => $paged,
) );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part( 'partials/content', 'teaser' );
endwhile;
else :
get_template_part( 'partials/content', 'none' );
endif;
/* Restore original Post Data */
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment