Skip to content

Instantly share code, notes, and snippets.

@bryankimani
Forked from FernE97/tabbed_taxonomy.php
Created November 19, 2015 08:12
Show Gist options
  • Save bryankimani/cf5051f47d493900348a to your computer and use it in GitHub Desktop.
Save bryankimani/cf5051f47d493900348a to your computer and use it in GitHub Desktop.
PHP: WordPress custom taxonomy/post query
<?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