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
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.
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
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:
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:
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.
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.
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);
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?
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.