Skip Navigation

[Resolved] Updating %%COUNT%% in select options with "Show only filter options " … off

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by blazM-4 3 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#2091449

Tell us what you are trying to do? I would like to have all options in filter search select fields but also (%%COUNT%%) updated.

Is there any documentation that you are following? couldn't find any. But I can do some JS and/or PHP.

Is there a similar example that we can see? any custom search but you can have either all options displayed OR counts updated

What is the link to your site? grantly.eu/sl/grants

#2091689

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2021-06-17 at 16.02.47.png
Screenshot 2021-06-17 at 16.02.26.png

You can manually enter the format you want to output the field options with in the settings for the search filter, mixing the placeholders, so that you can use for example %%NAME%% (%%COUNT%%) as shown in the screenshot, together with the results.

#2091891

Nigel, thank you for the prompt response.
But, I know how to create the counts.
The question was, how can I have these counts updated, despite having the "Show only filter options that would produce results" option turned OFF. When I have this option ON, the updating of counts during AJAX refresh works, when it is OFF, it doesn't.

I would like to have:
1. AJAX automatic refresh
2. counts updated with each refresh
3. All options displayed, with count=0, too

Sorry for not being clear.

#2092307

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2021-06-18 at 07.57.23.png

OK, thanks for the clarification, I understand you want the filter values to update to be consistent with the current search results, but rather than have options that would produce no results disappear you want them to continue to be displayed, but with a zero count.

This would be possible with the legacy Views editor, but the same options did not get implemented in the View block.

If you see the screenshot of settings that are available in the Custom Search Settings of a legacy View when you opt to choose individual settings manually, you have the option of whether to hide unavailable options or whether to disable them (but continue to show them).

If you wanted to avail of that setting I'm afraid you would need to recreate the same View using the legacy editor rather than the block editor.

If you want to try that, although the UI is different the concepts are the same.

Go to Toolset > Settings and make sure that the legacy editor is available (you'll probably want the option to show both), and then go to Toolset > Views to make a new View using the legacy editor. When finished you can insert this existing View using the View block.

#2092323

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Actually, before you go down that route, we have an API filter where it is possible to override the View settings.

I haven't tested it to see that it would work in this scenario, where the settings are missing from the View block, but I think it should if you want to give it a try with your existing View made using Blocks.

This is the filter: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_view_settings

Here is an example of how to use it to override the same settings shown in the previous screenshot, so that the option is disabled rather than hidden:

add_filter( 'wpv_view_settings', 'ts_filter_view_settings', 10, 2 );
function ts_filter_view_settings( $view_settings, $view_id ){

    if ( $view_id == 58 ) // Edit 
    {

        $view_settings['dps']['empty_select'] = 'disable';
        $view_settings['dps']['empty_multiselect'] = 'disable';
        $view_settings['dps']['empty_radios'] = 'disable';
        $view_settings['dps']['empty_checkboxes'] = 'disable';
    }

    return $view_settings;
}

Let me know if that works.

#2093841

Nigel, thank you for very informative answer. It taught me a lot.

And it works as you said. But, I didn't mention I needed the options with (0) not just to show up, but also be check-able.

It is because I need this custom filter to work on the view output (in its regular function), but also to serve as a configurator for email notifications when a new record appears that fits the criteria. This means, I want the users to be able to select also the options that make no difference in that moment but serve as a setting for the future.

Sorry for not explaining this immediately. Can it be done?

#2094157

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Unfortunately the logic of this is all tied together, the %%COUNT%% placeholder will only update if you have the option active to only show filter values that will produce results, and there the option is to hide options that would produce results or to disable them.

However, I expect that the options are disabled simply by adding the disable attribute to them.

So you should be able to add a little JavaScript snippet that strips the disable attribute from any of the options which have it.

#2094429

Yes, it works, thank you very much.
I just used a set of

jQuery("#XXXXXX input:disabled").prop( "disabled", false );

and it works great.

My issue is resolved now. Thank you!