Skip Navigation

[Resuelto] How to show search items conditionally to what was queried for

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How can I show certain search items based on other search parameters, like "if you search by A for xy, then show Search by B, otherwise not"

Solution:
https://toolset.com/forums/topic/search-filter-taxonomies-approach/#post-1142916

This support ticket is created hace 6 años, 1 mes. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Este tema contiene 11 respuestas, tiene 2 mensajes.

Última actualización por Akhil hace 6 años.

Asistido por: Beda.

Autor
Mensajes
#1136594

Hi Nigel, good day. I need some guide here on the approach i should plan before jumping in.

As you know i have cpt: directories, inside that there is cat, subcat, , there is also custom fields in group.

Now i need to achieve this.

When user reach certain category, the appropriate field should should appear. before that all should hide, only display the generic search fields.

example: for cat: food, to show field group food .

since its goes by url to reach the categories, is js appropriate to hide and show the tabs. ?

the archive setting to :show/hide the filter that not in use" is not helping for me .

Thanks.

#1137479

Nigel is on vacation, maybe I can help.

Can you show me where you plan to implement this and how the field is related to the Term (Taxonomy)?
I think you can work with HTML conditions, checking up on the current term or URL parameter or similar and conditionally show Fields or not.
HTML conditionals are explained here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1137555

Hi Beda, its here: enlace oculto

#1138080

Please explain to me where you want to do what, I am not sure to follow.

On the site provided, there is no cat, food or similar terms or fields, I did not find them.

I am also not sure what you want to hide or show, as I see a listing of 6 entries, which seem to be locations.

Is your plan to hide those locations until a certain URL is reached (such as a Taxonomy archive)?
Then you need to style that archive in Views and hide the elements with HTML conditions as shown here:

https://toolset.com/forums/topic/search-filter-taxonomies-approach/#post-1137479

I have activated a private reply where you also can refer to internal (access data required) screens on your site so I can understand better the need and help to find the solution.

#1138796

Hi Beda, thank you. pls allow me some time to prepare a staging site for you. ill update when its ready.

not sure why you cant see the fitlers, maybe it was in editing mode.
meanwhile, you can visit the page again at : enlace oculto ,

what i need to achieve is to hide and show the filters group when certain url/taxonomies is reached.

i am guessing this could be achieved with custom script ? or is there any other way ?

#1138885

I think I understand now, I saw those filters but could not find the particular terms you mentioned so I was not sure it's the one.

Now, whatever you want to hide on the site, depending on what was chosen in the Filter, can only be done by listening to the URL parameters of that filter.

Let's say, I click on the filter to filter by any Taxonomy Term
This will generate some new URL (either by AJAX or not) that reflects this query.
This ONLY works if you show the search terms in the URL, and it seems you are using the AJAX updated and URL hidden method.
Hence, that won't work with the usual methods, and even if you show the Search query in the URL, you can hide only partials of your search.
In that case, you can listen to the ShortCode wpv-search-term and if it is the value you check upon either hide or show entire Filters with HTML conditionals.
It is NOT possible to hide SINGLE items of a Select of the same filter, depending on what was selected.
This is only possible if you hide "empty" items, means, if selection A would return no results in selection B then that option would be possible to be removed or disabled.
That, is only WITHIN the same filter, while HTML conditions are for a whole set of a filter (for example, to hide an entire Category filter, but not just single options of it)

As you see, it will be complex.

Can you precisely elaborate to me, in that filter on the left side, what exact sections or terms you would have to be removed when?

The example of hiding an entire section with HTML conditional when a certain search is run:

[wpv-conditional if="( '[wpv-search-term param='url_param_you_listen_to']' eq 'what you search for' )"]
  put the search section to hide in here
[/wpv-conditional]

Above will show "put the search section to hide in here" only if you search for "what you search for" in the filter "url_param_you_listen_to".

Please let me know if this would help, but it hides only entire sections, not single options.
Single options, as said, can be hidden only for single searches, when you "Let me choose individual settings manually", and then "Show only available options for each input", in the Custom Search Settings.

#1138900

Nice, at least there is a hope. Previously i tried PODs it doesnt come anywhere close to achive this. great on toolset.

so in summary, i need to forgo ajax, select hide the empty item/filters , and use wpv-search term to condition the filter sets.

Yes, i need to hide the enter filter group.

example scene:
intially hide "f&b filters, kids features" .

when reach : enlace oculto and it's sub categories like

enlace oculto
enlace oculto

the above mention 2 sets of group filter should appear back..

Thanks !

#1138934

Yes, that can be done as said with HTML conditions, I can however not set this up for you from here, you would have to click on the "Conditional" button and set up the conditions around the content as explained in the DOC

To first hide the content you can, for example, check if the search parameter is '' (empty).
Hence, as long nothing is searched for that section remains hidden.
Or you can directly pass the value you mention so to show it only if you search by it.

But, the URLs you show me are not queries, those are Archive URL's, hence you cannot listen to the wpv-search-term ShortCode as that one only listens to /?search_param=

This is almost not possible on an archive as there is no inbuilt ShortCode to return the current archive URL or slug, you would have to create your own shortcode here.

However, could you grant me access first, as admin, and link the View/Archive where you want to do this?
I can then see if I can find a better solution.
Best would be access to a test site so I can make changes.
Please mention if this is not allowed.

#1142026

I have set up a working example for you that listens to the Free Text Search (wpv-filter-search-box) and only will show if it's searched value is "this":

[wpv-conditional if="( '[wpv-search-term param='wpv_post_search']' eq 'this' )"]I am hidden at begin, and show only if I search for "this" in the Free Text Search (wpv-filter-search-box)
Similarly you can listen to other Search URL parameter from other inputs.[/wpv-conditional]

This is not visible on load:
enlace oculto

It becomes visible once you search for "this" in the free text search and submit that search:
enlace oculto

Similarly, you can hide entire filter sections based on whether or not other filters are used.
The URL parameters you can get from the Query Filters Options or from the front end when you submit the Search.

#1142474

Thanks. i would apprecite more sample on this conditional.

1.hide entire filter sections based on whether or not other filters are used.
2. hide entire filter sections based on url .

i tried something to use [wpv-post-url] but it need fetches only the main url.

#1142916

This example can be created with the GUI when you press "Conditional" button, then you replace the ShortCode it generates (data source) with "Views and Fields" ShortCodes, where you can then pass the attributes to it.

[wpv-conditional if="( '[wpv-search-term param='wpv_post_search']' eq 'this' )"]

I am hidden at begin, and show only if I search for "this" in the Free Text Search (wpv-filter-search-box)
Similarly you can listen to other Search URL parameter from other inputs.
Put whatever you want in here, for example, entire Search ShortCodes.

[/wpv-conditional]

The entire trick consists in manipulating [wpv-conditional if="( '[wpv-search-term param='wpv_post_search']' eq 'this' )"]

For example we can say "if we did not yet search in the free text search, hide me". This translates to "If there the query is NOT empty, then show me".

[wpv-conditional if="( '[wpv-search-term param='wpv_post_search']' ne '' )"]

Or, you can say to listen to a total different Search, let's say the Category.
If you search for category ABC, then show the content:

[wpv-conditional if="( '[wpv-search-term param='wpv-category']' eq 'ABC' )"]

Please consult our DOC as well, which has a lot of examples:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

As said, you cannot receive the URL in an archive, but there is also no need for since you can listen to the Query Parameters and you have a Custom Search there, hence producing such parameters.

#1144471

My issue is resolved now. Thank you!