Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $current_taxonomy = get_query_var( 'taxonomy' );
- $current_term = get_query_var( 'term' );
- // projects are filtered by term
- if( $current_taxonomy && $current_term ) {
- $projects = get_posts(
- array(
- 'post_type' => 'my-post-type',
- 'posts_per_page' => 10,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'my-taxonomy',
- 'field' => 'slug',
- 'terms' => $term->slug
- )
- )
- )
- );
- if( $projects ) {
- foreach( $projects as $project ) {
- ?>
- <section class="">
- <?php
- echo $project->post_title;
- ?>
- </section>
- <?php
- }
- }
- } else {
- // projects are not filtered
- // we show projects by all terms
- $terms = get_terms(
- array(
- 'my-taxonomy'
- ),
- array(
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'hide_empty' => true
- )
- );
- foreach( $terms as $term ) {
- $projects = get_posts(
- array(
- 'post_type' => 'my-post-type',
- 'posts_per_page' => 10,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'my-taxonomy',
- 'field' => 'slug',
- 'terms' => $term->slug
- )
- )
- )
- );
- if( $projects ) {
- foreach( $projects as $project ) {
- ?>
- <section class="">
- <?php
- echo $project->post_title;
- ?>
- </section>
- <?php
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement