I have built an isotope portfolio Wordpress theme which so far is working perfectly:
Anything posted in the custom post type 'portfolio' shows on the homepage and is filterable by the 'portfolio-category' taxonomy using the Isotope JQuery plugin.
So far so good.
However, I wish to make a small improvement.
I only want FEATURED portfolio items to show on the homepage. For example, only portfolio items with the taxonomy classification of 'featured'. This part I have achieved easily with a custom query (see code snippet below).
The problem I am having is displaying the filterable buttons. I don't want a filterable button to say 'Featured' (defies the point), nor do I want any taxonomies to appear which aren't applicable to any of the featured items (because if clicked, all the portfolio items being displayed will disappear).
Here is my current query to show the portfolio items. No problems here:
<?php
// Query the portfolio posts
$args = array(
'post_type' => 'portfolio',
'portfolio-category' => 'featured',
'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<!-- PORTFOLIO ITEM -->
<?php endwhile; ?>
And here is the code I have currently which outputs the filterable taxonomies. This is what needs addressing.
<?php
$terms = get_terms('portfolio-category');
$count = count($terms);
echo '<li class="filtering"><a href="#" title="" data-filter="*" class="button-primary">All</a></li>';
if ( $count > 0 ){
foreach ( $terms as $term ) {
$termname = strtolower($term->name);
$termname = str_replace(' ', '-', $termname);
echo '<li class="filtering"><a href="#" title="" data-filter=".'.$termname.'">'.$term->name.'</a></li>';
}
}
?>
Many thanks!