Skip Navigation

[Resolved] Conditional, URL parameters and parametric search

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

Problem: I have a conditional in my View output editor that tests the value of a search term / URL parameter using the [wpv-search-term] shortcode. When I update the View results using AJAX, the conditional stops working.

Solution: Add a hidden field in your filter controls that contains the value of the search term from a URL parameter. Add the 'js-wpv-filter-trigger' class to this input to send the search term along every time the filters are updated.

<input type="hidden" name="id_demande" value="[wpv-search-term param='id_demande']" class="js-wpv-filter-trigger" />

Use the search term shortcode in your conditional:

[wpv-conditional if="( '[wpv-search-term param='id_demande']' ne '' )"]<td></td>[/wpv-conditional]

Relevant Documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#556842

Hello,
I have set a view loading a table where the first column should be shown only if "id_demande" url parameter is set.

[wpv-conditional if="( '[wpv-search-term param="id_demande"]' ne '' )"]<td></td>[/wpv-conditional]

Everything works fine, except that on frontend, when the user modifies the parametric search filters, the column disappears... but the URL still has the parameter !
Would this be a bug ?
Thank you.

#556989

Does this View update using AJAX? If so, the original value when the page loads is the only value that will be considered.

#557011

Yes it is using AJAX.
The filters don't change the original value of the url parameter, but still, the button disappears.
I deactivated "Do not adjust URLs after loading search results" with no change.
Could you please activate private fields so I can send you the URL showing the bug ?
Thnak you.

#557016

Private reply fields enabled here.

#557052

The [wpv-search-term] shortcode only applies to the first set of search results, because the AJAX searches after that do not include the id_demande search parameter like you include in the original search filters. Each AJAX search will not reference the original search parameters, only the new ones selected in your View's filters. If you want to include id_demande in your AJAX calls, you could try to add it as a hidden field in the Filter Controls editor:

<input type="hidden" name="id_demande" value="[wpv-search-term param='id_demande']" />
#557054

Hello,
I've just tried it without result.
Thank you.

#557057

I see. I'm not sure if there is a good way to accomplish this, but I will continue to investigate and update you tomorrow when I return to work. Thanks for your patience.

#557909

I see now, you must add the class "js-wpv-filter-trigger" to your hidden input field in order to use this value in your conditional:

<input type="hidden" name="id_demande" value="[wpv-search-term param='id_demande']" />

You should then find the information included in the post to admin-ajax.php, and the conditional in your View output should work correctly. I recommend modifying the nested quotes to only use one set of double quotes, with single quotes inside those double quotes:

[wpv-conditional if="( '[wpv-search-term param='id_demande']' ne '' )"]<td></td>[/wpv-conditional]
#558036

Just add the class and it worked perfectly !
Thank you very much.