Forums › Forums › Search & Filter Pro › Total Count
Tagged: V3
- This topic has 6 replies, 3 voices, and was last updated 4 years, 5 months ago by Anonymous.
-
Anonymous(Private) June 26, 2020 at 7:52 am #250165
Hi Support,
I create the taxonomy LEVEL: Basic(1), Intermediate(1), Advanced(1).
I selected the dropdown style and the first filter displayed is All Levels but do not show the total count.
As an alternative solution I created a new taxonomy called All Levels and now shows the total of (3). Also I had to rename the lable to By Level to do not look duplicate. I don’t see a reason for this as the feature is already showing all the videos but the only thing missed is the total count of all sub items.Is there any better solution?
Thank you,
Maurino LoureiroRoss Moderator(Private) June 30, 2020 at 9:16 am #250604Hi Maurino
We have a WP / PHP hook which you can use to modify each individual option in your field – you could then loop through all your options, count the total results, and add that to the first option (All Items) – this is the filter: https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
I’ve actually gone ahead and managed to create a code snippet for you that does this:
function add_count_to_first_option( $input_object, $sfid ) { // if the field doesn't have input options, then leave it alone if ( ! isset( $input_object['options'] ) ) { return $input_object; } $total_count = 0; // loop through each option and add up the total count foreach ( $input_object['options'] as $option ) { if ( isset( $option->count ) ) { $total_count += absint( $option->count ); } } // now check to make sure there was a first option (with value of "") // and update its count if ( isset( $input_object['options'][0] ) ) { if ( '' === $input_object['options'][0]->value ) { $input_object['options'][0]->label .= ' (' . $total_count . ')'; } } return $input_object; } add_filter('sf_input_object_pre', 'add_count_to_first_option', 10, 2);
Add this to your themes functions.php, and that will add a count to all first options in your fields.
Thanks
-
AuthorPosts