Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Total Count

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Maurino Loureiro
    #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 Moderator
    #250227

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

    Maurino Loureiro
    #250297
    This reply has been marked as private.
    Ross Moderator
    #250357
    This reply has been marked as private.
    Maurino Loureiro
    #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

    Maurino Loureiro
    #250672
    This reply has been marked as private.
Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.