Total Count

Forums › Forums › Search & Filter Pro › Total Count

Tagged: 

Viewing 7 posts – 1 through 7 (of 7 total)
  • Anonymous
    #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?

    http://www.jiujitsubase.com

    Thank you,
    Maurino Loureiro

    Trevor
    #250227

    I have referred this to the plugin developer, Ross, for his input.

    Anonymous
    #250297
    This reply has been marked as private.
    Ross Moderator
    #250357
    This reply has been marked as private.
    Anonymous
    #250573
    This reply has been marked as private.
    Ross Moderator
    #250604

    Hi 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

    Anonymous
    #250672
    This reply has been marked as private.
Viewing 7 posts – 1 through 7 (of 7 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.