So I have a Custom Post Type with some Custom Taxonomies.
On the archive
page where I list all the Custom Post Types I have an refine search in the sidebar which allows you to tick a Taxonomy Term and then search for Post Types with that Term. (Image Below)
When you click say ‘Cellar’ it reloads the page and shows you the result (in this instance it’s only one Post Type)
My question is: How do I update the numbers on the side of the names so if ‘Cellar’ is checked then the number next to ‘Carpet’ should update to say (1)
because there is only 1 property with the ‘Cellar’ and ‘Carpet’ term together
Here is the code controlling the output of the number but at the moment this is just static and is just count every Post Type with that term.
<?php
$all_features = get_terms('features');
/* Features in search query */
$required_features_slugs = array();
if( isset ( $_GET['features'] ) ) {
$required_features_slugs = $_GET['features'];
}
$features_count = count ($all_features);
if($features_count > 0) {
?>
<div class="more-options-wrapper clearfix">
<?php
foreach ($all_features as $feature ) {
?>
<div class="option-bar">
<input type="checkbox"
id="feature-<?php echo $feature->slug; ?>"
name="features[]"
value="<?php echo $feature->slug; ?>" onclick="document.getElementById('refine-properties').submit();"
<?php if ( in_array( $feature->slug, $required_features_slugs ) ) { echo 'checked'; } ?> />
<label for="feature-<?php echo $feature->slug; ?>"><?php echo $feature->name; ?> <small>(<?php echo $feature->count; ?>)</small></label>
</div>
<?php
}
?>
</div>
<?php
}
?>
I have put an example below:
The Images above represent what I am trying to do