Skip Navigation

[Resolved] Search Filter with additional Query Filter no longer possible

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add multiple taxonomy filters on same taxonomy into post view.

Solution:

In this case, it needs custom JS/CSS codes, for example:

https://toolset.com/forums/topic/search-filter-with-additional-query-filter-no-longer-possible/#post-2165473

Relevant Documentation:

This support ticket is created 2 years, 8 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.

Our next available supporter will start replying to tickets in about 2.40 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 19 replies, has 3 voices.

Last updated by simonM-5 2 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2131761

Hi Support

I'm running into issues again using the basic Search Filters functionality.

I have a Custom Post Type FAQs and want to give the users the possibility to filter by the custom Taxomony "FAQ Categories" on our FAQs page. However, I only want certain FAQ Categories to be allowed to retrieved in the View. For example, let's say I have 10 FAQ Categories A-J. I want to let the users filter only by FAQ Categories A, B, F and G (eg as checkboxes) on the Front end, and only allow FAQ posts associated to those FAQ Categories to be retrieved from the query.

If I add the New Filter "FAQ Categories" to the Search and Pagination pane in the View, then I cannot set a query filter to limit the View to only show Categories A, B, F and G on the front end, because when I click the +Add a Filter button, "FAQ Categories" is greyed out.

Similarly, the other way round, if I start with the +Add a Filter button, I am able to limit the view to only the 4 FAQ Categories I want displayed on the front end, but then I cannot choose the FAQ Categories as a new Filter item in the Search and Pagination pane, in order to display the checkboxes as filter options.

I'm pretty sure this is the same problem that was due to the change in a recent version of the Views plugin, as confirmed by Nigel in our recent ticket a few weeks ago, (https://toolset.com/forums/topic/ajax-search-showing-incorrect-behaviour-in-search-filters/page/2/#post-2109161), which I feel is a step backwards in terms of functionality and flexibility of the search. In fact the search functionality detailed in that ticket changed in such a way, that we are not actually getting the desired search results that would be expected - which will be even more confusing for the users.

Feel free to have a play with the View "FAQ Search and Results View" on this site to try to achieve the required results.

Can you please advise:
1) how I can achieve this simple query in the FAQs (this ticket) to get past this either/or situation as it appears now? I need to be able to add a Filter to the Search and Pagination pane AND add an additional query filter based on the same item (FAQ Categories) to the Query Filter section.

2) Nigel talked in our previous ticket about "Legacy Views", as opposed to Blocks. In https://toolset.com/forums/topic/ajax-search-showing-incorrect-behaviour-in-search-filters/page/2/#post-2113033, Nigel says:

"The changes originate in how Blocks handles search filters so that rather than explicitly adding a Query Filter for each front end filter the underlying query gets generated on-the-fly (dynamically), and the effect on legacy Views is that although you can see the Query Filters that correspond to the front-end filters, you shouldn't be able to edit them, the editing needs to be of the front-end filter itself (which in a legacy View is the shortcode to generate the front-end filter).

The issue on your site is not that you cannot edit the Modes of Transport Query Filter—you shouldn't be able to—it is that you can edit the other Query Filters that correspond to front-end filters. And that's what I've escalated for the developers to investigate.", however the ticket closed before I got a chance to get back to it.
How can I go about addressing the incorrect search results appearing in the previous ticket? Should I reopen a new ticket referring to the previous one?"

Is Toolset planning to phase "Legacy Views" out altogether at some point in the future and only leave us with Blocks?!!

Thanks and best regards
Simon

#2132325

Hello,

I assume we are talking about the page of your website:
hidden link

And post view "FAQ Search and Results View":
hidden link

You can add one filter on same taxonomy "FAQ Categories", this is an limitation of Toolset plugins, but you can try with custom codes, for example, use wpv_filter_query to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Add a taxonomy filter into query, and setup those specific terms you want:
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

#2132331

Hi Luo

Is this limitation new? And if so, since when? I'm pretty sure that before it was possible to have a Search Filter and a Query Filter set on the same criterion.

Another possible solution I thought of was to duplicate the taxonomy so I could use one version of it to filter the checkboxes shown to the user on the front end, and the other version to limit which records get returned in the view.

Would you consider that to be a viable solution?

Kind regards
Simon

#2133463

This is not a old limitation, you can try with Toolset Views plugin, you should be able to see the same limitation.

As I mentioned above, you can setup only one filter on same taxonomy using UI, but you can use filter hook wpv_filter_query to add multiple filters on same taxonomy, see the documents I mentioned above:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

#2134485

OK, thanks for the confirmation Luo.

Do you know of any plans to lift this limitation via the GUI? It would make it so much easier to manage and adapt the query sent to the database. It's almost torture seeing the options there on the GUI and not being able to use them hahaha :-))

Kind regards
Simon

#2134541

Unfortunately, there isn't any plan lift this limitation, but you can add a feature request for it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Our developers will evaluate it.

#2137435

Hi Luo

OK, I'll have to workaround this. In a previous update, I suggested:
"Another possible solution I thought of was to duplicate the taxonomy so I could use one version of it to filter the checkboxes shown to the user on the front end, and the other version to limit which records get returned in the view."

Would you consider that to be a viable workaround?

Cheers
Simon

#2137895

Hi
I added the feature request in the meantime.
Cheers
Simon

#2138413

I don't think it is good idea to use two duplicated taxonomies, this will conducts lots of problem.

As I mentioned above, you can setup only one filter on same taxonomy using UI, but you can use filter hook wpv_filter_query to add multiple filters on same taxonomy, please let me know if you need assistance for it. thanks

#2138523

Hi Luo

My main concern is being able to build an FAQ Search and Results page with checkboxes for the below 4 FAQ categories, returning only those FAQs linked to these FAQ categories. All the remaining FAQs are "single" FAQs specific for specific pages and don't belong on our FAQ page.
- Help Page
- Native Nanny
- Family
- Technical Support

If you could assist with a generic example or something, I'd be very grateful!
The CPT is: nn-faq
The custom taxonomy is: nn-faq-categories

Originally I had hoped that all this would have been possible via Elementor Pro Accordion widget, which is predestined for FAQs, but I couldn't get it to use Dynamic Content properly. It only seemed to work with Toolset Custom fields, so I created the custom fields FAQ Question and FAQ Answer, which in itself seemed crazy to me, since FAQ Question is just the Post Title and FAQ Answer is just he Post Content copied. Furthermore, it wouldn't have allowed me to filter by my FAQ Categories taxonomy, so that's why I decided it might be better to use a Toolset View to allow a search capability as well.

Out of curiosity, what are the "lots of problems" you imagine from my solution of 2 taxonomies instead of 1? Surely they are distinct query criteria and don't "know about each other"? I would imagine them to have the same terms but just be part of a different taxonomy.

Thanks and regards
Simon

#2138735

I have done below modifications in your website:
1) Edit post view "FAQ Search and Results View"
hidden link
In section "Query Filter", remove the existed taxonomy filter
in section "Search and Pagination", add a search field on taxonomy "nn-faq-categories"

2) Dashboard-> Toolset-> Settings-> Custom codes, add a new item "additional-query-filter":
hidden link

With below codes:

add_filter( 'wpv_filter_query', 'additional_query_filter_func', 999, 3 );
function additional_query_filter_func( $query_args, $views_settings, $view_id) {
    $view_ids = array( 17100 ); // specify Views IDs
    if (in_array($view_id, $view_ids)){
        if(!isset($query_args['tax_query'])){
            $query_args['tax_query'] = array();
        }
        $query_args['tax_query'][] = array(
            'taxonomy' => 'nn-faq-categories',
            'operator' => 'IN',
          	'field' => 'slug',
          	'terms' => array('nn-faq-help-page', 'nn-faq-native-nanny', 'nn-faq-family', 'nn-faq-techsupport'), // Specify term slugs
        );
    }
    return $query_args;
}

Test it in frontend:
hidden link

It works fine, please check if it is what you want. thanks

#2140217

Hi Luo

I have tested this and it is not quite working 100%. On the initial page load, only those 4 categories are presented, however after conducting a Search, all the categories appear again.

I changed from a dropdown to checkboxes, but the effect is the same even if you use a dropdown.

Kind regards
Simon

#2164661

Hi Luo

Are there any updates here? I haven't heard anything from you on this topic for 4 weeks.

Thanks and regards
Simon

#2165473

Sorry for the delay answer, there is a CSS/JS workaround: you can use CSS/JS codes to hide other options, for example, edit the post view "FAQ Search and Results View":
hidden link
1) In section "Search and Pagination",
line 6, change the codes from:

<div class="form-group">

To:

<div class="form-group nn-faq-categories-checkboxes">

In box "CSS editor", add below CSS codes:

div.nn-faq-categories-checkboxes div.form-check{
	display:none;
}

In box "JS editor", add below JS codes:

jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.view_changed_form (object) The jQuery object for the View form after being updated
	* data.view_changed_form_additional_forms_only (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-form-view] shortcode
	* data.view_changed_form_additional_forms_full (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-view] shortcode
	*/
  
	show_specific_terms();
});
show_specific_terms();

function show_specific_terms(){
	jQuery('input[value="nn-faq-help-page"]').parent('div.form-check').show();
	jQuery('input[value="nn-faq-native-nanny"]').parent('div.form-check').show();
	jQuery('input[value="nn-faq-family"]').parent('div.form-check').show();
	jQuery('input[value="nn-faq-techsupport"]').parent('div.form-check').show();
}

Please test again, check if it is what you want.

#2165647

Hi Luo

Thanks for the update.

1) I tested in English and it seems to work there, however when we switch to German, we don't even see the 4 categories.
2) Also, when we click an FAQ to open it, they all open at once, instead of just the one opening and closing.
3) Is the underlying bug for which we need to use JavaScript/CSS workarounds being addressed by development? I feel that this FAQ use case is such an obvious one that many are likely to want to have on their website and I'm a little disappointed that such a simple use case is not easily achievable using the standard GUI controls.

Kind regards
Simon

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.