-
-
Save bryankimani/cf5051f47d493900348a to your computer and use it in GitHub Desktop.
PHP: WordPress custom taxonomy/post query
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
<?php | |
$args = array( | |
'orderby' => 'ID' | |
); | |
$terms = get_terms( 'testimonial_category', $args ); | |
?> | |
<!-- bootstrap tabs --> | |
<ul class="nav-tabs"> | |
<?php | |
$count = 0; | |
foreach ( $terms as $term ) : $count ++; ?> | |
<li<?php if ( $count == 1 ) echo ' class="active"' ?>> | |
<a href="#<?php echo $term->slug ?>" data-toggle="tab"><?php echo $term->name ?></a> | |
</li> | |
<?php | |
endforeach; ?> | |
</ul> | |
<div class="tab-content"> | |
<?php | |
$count = 0; | |
foreach ( $terms as $term ) : $count ++; ?> | |
<div class="tab-pane <?php if ( $count == 1 ) echo 'active' ?>" id="<?php echo $term->slug ?>"> | |
<?php | |
$args = array( | |
'post_type' => 'testimonial', | |
'tax_query' => array( | |
array( | |
'taxonomy' => $term->taxonomy, | |
'field' => $term->slug, | |
'terms' => $term->term_id | |
) | |
) | |
); | |
$loop = new WP_Query( $args ); | |
if ( $loop->have_posts() ) : | |
while ( $loop->have_posts() ) : $loop->the_post(); ?> | |
<blockquote class="testimonial-<?php the_ID(); ?>"> | |
<?php the_content(); ?> | |
</blockquote> | |
<cite><?php the_title(); ?></cite> | |
<?php | |
endwhile; | |
endif; wp_reset_query(); | |
?> | |
</div><!-- end tab-pane --> | |
<?php endforeach; ?> | |
</div><!-- end tab-content --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment