Skip Navigation

[Closed] Filters not working

This support ticket is created 4 years, 9 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+01:00)

This topic contains 12 replies, has 3 voices.

Last updated by Nigel 4 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1834457

I am trying to:
Use the filtering system here: hidden link
It used to work fine, but now the taxonomy filtering is not returning results or returning the wrong results.

Link to a page where the issue can be seen:
hidden link

I expected to see:
Working filtering.

Instead, I got:
Filtering that isn't working.

#1834597

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Vadim,

Thank you for getting in touch.

During my quick checks to see if I can filter down to a single post, I was able to find that post in the search.

Can you take a screenshot of the search criteria you are using and what post should be the expected result? Based on what I see the search is actually working fine.

Thanks,
Shane

#1835463
Screenshot_84.png
Screenshot_85.png
Screenshot_86.png

Hi, Shane!

See attached screenshots to see which filter is selected (that is the only filter selected currently, but the same thing happens with all of them) as well as which post should've been found but wasn't, which is this one:
hidden link

Thanks,
Rob

#1835729

Nigel
Supporter

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

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

Screenshot 2020-11-05 at 15.52.37.png

It looks like the problem is because you also have a custom field filter for location, and that gets applied at the same time as selecting your certification taxonomy filter.

See the screenshot of the debug info for the View query generated when I select the same taxonomy term as in your own screenshot. (You can activate/de-activate the debug mode at Toolset > Settings > Front-end Content.)

The difficulty is that you have a filter for the location custom text field displayed as a Select dropdown, and there is no empty option, so you will always be submitting some value for this filter whether you intend to or not.

For that kind of filter—a single line field displayed as a select dropdown—there is no option to add an empty value.

The only way to do it is to insert one yourself with JavaScript/jQuery.

The markup on the front-end for that filter is like so:

<select id="wpv_control_select_wpcf-location" name="wpv-wpcf-location" class="js-wpv-filter-trigger form-control">
  <option value="Киев: UTC +2">Киев: UTC +2</option>
  <option value="Москва: UTC +3">Москва: UTC +3</option>
  <option value="Рига: UTC +2">Рига: UTC +2</option>
</select>

So you need to insert a blank option (with a empty string for the value).

The following should achieve that, but I leave it to you to test it:

(function ($) {
    $(document).ready(function () {

        $('select[name="wpv-wpcf-location"]').prepend('<option value="" selected>--Choose--</option>');

    });
})(jQuery);

You can add it to the custom JS section of your search and pagination editor.

#1838713

Nigel
Supporter

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

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

Let me know how you get on and if we can close here...

#1839771

Hi, Nigel!

We are testing the solution right now and will get back to you. Please don't close the ticket yet 🙂

#1845519

Nigel
Supporter

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

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

Let me just mark this threads as awaiting your reply so that it's not sitting in my queue.

#1848091

HI! 🙂

Thank you for waiting.

We have reviewed and it's working better now but not at a 100% yet.
The main issue is this:
When I choose just filter by "CRRC ECF" certificate it gives me 2 correct results (Юрий Галата and Илона Галата). But in the same time it automatically choose "Рига: UTC+2" in "Страна работы коуча", so after it is hard to continue filtering because all results are not right. Reloading page and button "Удалить фильтры"(reset filters) are not helping, helps just clicking on "Найти коуча"(just going to the page again from nav) in the main menu

To fix this, I assigned the function you provided to another event, one of yours, so the code we use now is this:

(function ($) {
		$(document).on('js_event_wpv_parametric_search_results_updated', function () {

			$('select[name="wpv-wpcf-location"]').prepend('<option value="" selected>--Choose--</option>');

		});
	})(jQuery);
	
	(function ($) {
		$(document).ready(function () {

			$('select[name="wpv-wpcf-location"]').prepend('<option value="" selected>--Choose--</option>');

		});
	})(jQuery);

But now this continues to give us some bugs, namely: when we select one of the cities/locations, it gives us the result but the location then resets to the empty option. this is because of the event that triggers the function on results update. And removing "selected" from the HTML doesn't work, of course, because then we get back to the first issues once we hit "reset filters".

Can you recommend a solution? You still have the access to our website and we would love some help.

Thanks

#1849719

Nigel
Supporter

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

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

This is proving trickier than I expected.

If your custom field were a select field it would be easy enough because you could add the empty defauly option in the field settings itself or use a PHP filter to modify the options, but in your case you are using Single Line text fields and then presenting them as a select dropdown.

I'm trying to test the URL to see if the filter has been applied (if the wpv-wpcf-location parameter is set) but window.location.href is giving me the wrong results because it appears we update the URL after the custom Views events are fired.

I'm checking with the devs if there is some way around that and I'll get back to you.

#1854515

Hi, Nigel.

Any news on this?

Thanks

#1855569

Nigel
Supporter

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

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

OK, I took a slightly different approach and I've tested the following on my own site and it seems to work in the different scenarios.

The only issue is that there is a visual glitch where the select dropdown is reset, but that is unavoidable given that a timeout needs to be set to wait for the URL to be updated.

Here's the code:

(function ($) {

    const insertOption = function(){

        var selected = "";
        if ( window.location.href.indexOf( 'wpv-wpcf-location') === -1 ){
            selected = "selected";
        }
        $('select[name="wpv-wpcf-location"]').prepend('<option value="" '+selected+'>--Choose--</option>');
    }

    $(document).on('ready', insertOption );

    $(document).on('js_event_wpv_parametric_search_results_updated', function () {

        // does the select already have an empty option?
        if ( $('select[name="wpv-wpcf-location"] option:first').val() != "" ){
            setTimeout( insertOption, 200 );
        }
    });

})(jQuery);
#1856401

Nigel!

Thanks, I will try this code.
Say, do you mean for this code to be used separately from the JS I already added before, or should this code replace the JS from before?

#1856403

Nigel
Supporter

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

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

It should replace the previous code, the logic is slightly different and should cover the different uses cases including using the clear filters button.

The topic ‘[Closed] Filters not working’ is closed to new replies.