I’m working with the Bones Development theme, and trying to create a filterable portfolio using WordPress Custom Post Types.
I’ve completed the plugin, and looked through it quite thoroughly, but it’s not filtering. It’s displaying all the posts, but the filters aren’t working.
I’ve generated the “data-filter” in the back-end using WordPress tags. Then for each filter, I’ve added the following:
[code=php]<?php
$terms = get_terms(“tagportfolio”);
$count = count($terms);
echo ‘<div class=”controls”><ul>’;
echo ‘<li class=”filter” data-filter=”all”>Show All</li>’;
if ( $count > 0 )
{
foreach ( $terms as $term ) {
$termname = strtolower($term->name);
$termname = str_replace(‘ ‘, ‘-‘, $termname);
echo ‘<li class=”filter” data-filter=”‘.$termname.'”>’.$term->name.'</li>’;
}
}
echo “</ul></div>”;
?>
Right after I start the loop, I call the following:
[code=php]<?php $terms = get_the_terms( $post->ID, ‘tagportifolio’ );
if ( $terms && ! is_wp_error( $terms ) ) :
$links = array();
foreach ( $terms as $term ) {
$links[] = $term->name;
}
$links = str_replace(‘ ‘, ‘-‘, $links);
$tax = join( ” “, $links );
else :
$tax = ”;
endif;
?>
In order to get these data-filters to apply to my grid, I’ve used the following php code:
[code=html]<div class=”threecol <?php echo strtolower($tax); ?>”>
Lastly, I’ve changed my selector from “.mix” to “.threecol”.
I’ve attached a screenshot of how it looks (note that the pink filters are linked states, and none of them are marked “active”). All of the items are being pulled from the WP backend, all of the tags in the filter list are showing up as the tags I have them listed as in the WP backend – but for some reason, it’s not working.
The only issue I can see is that the “<?php echo strtolower($tax); ?>” isn’t working to add the class name taken from the data-filter.
I feel like I’m getting very close, and feel like this is a simple fix. Any help would be appreciated!
[URL=”https://f.cloud.github.com/assets/5175139/2090618/c7fb02e4-8e96-11e3-8aae-d67dd9a3bb1f.png”]https://f.cloud.github.com/assets/5175139/2090618/c7fb02e4-8e96-11e3-8aae-d67dd9a3bb1f.png