Last active
August 29, 2015 14:17
-
-
Save Faisalawanisee/c3c18e4bf416b214c57c to your computer and use it in GitHub Desktop.
Custom Taxonomy in Wp Query
This file contains hidden or 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
<?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