Skip to content

Instantly share code, notes, and snippets.

@Faisalawanisee
Last active August 29, 2015 14:17
Show Gist options
  • Save Faisalawanisee/c3c18e4bf416b214c57c to your computer and use it in GitHub Desktop.
Save Faisalawanisee/c3c18e4bf416b214c57c to your computer and use it in GitHub Desktop.
Custom Taxonomy in Wp Query
<?php // Get all term ID's in a given Custom Taxonomy
$taxonomy = 'Custom Taxonomy';
$taxonomy_terms = get_terms( $taxonomy, array(
'hide_empty' => 0,
'fields' => 'ids'
) );
$args = array(
// Type Parameters
'post_type' => 'post',
// Taxonomy Parameters
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $taxonomy_terms,
),
),
// Pagination Parameters
'posts_per_page' => 7,
);
$query = new WP_Query( $args ); ?>
<?php if($query->have_posts()): ?>
<?php while($query->have_posts()): $query->the_post(); ?>
<?php endwhile; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment