Skip Navigation

[Resolved] Check on an URL Parameter with Toolset

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

Problem:
How can I check if a Custom URL parameter is set, or of a certain value?

Solution:
You can only use the Views ShortCode wpv-search-term

As an example:

[wpv-conditional if="( '[wpv-search-term param="my_term"]' ne '' )"]
  TEST
[/wpv-conditional]

The above sample code will output TEST only if the my_term URL parameter is not empty.
It works everywhere, as long Views is active.

Even if you pass no parameter at all, it still works great.

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term
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
- - 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)

This topic contains 3 replies, has 2 voices.

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

Assisted by: Beda.

Author
Posts
#556796

Hello,
I have created and declared the wpv-post-param shortcoode, which allows me to get a url param.
I have a view where this shortcode is used as a conditionnal, like this :

              	[wpv-conditional if="( '[wpv-post-param var='id_demande']' ne '' )"]
              		[toolset_access role="testrespachats" operator="deny"]
              			<th class="boutons">[wpv-heading name="choisir"][/wpv-heading]</th>
              		[/toolset_access]
              	[/wpv-conditional]
              	[wpv-conditional if="( '[wpv-post-param var='id_demande']' eq '' )"]
              		[toolset_access role="testrespachats" operator="deny"]
              			<th class="boutons">[wpv-heading name="commander"][/wpv-heading]</th>
              		[/toolset_access]
              	[/wpv-conditional]

But when the url parameter is not set in the url, the code returns an error. So instead of checking if the url parameter ='' or <>'', it seems I'd rather test if url parameter exists or not.
How could I do this ?
Thank you.

#556829

I think you can only use the Views ShortCode wpv-search-term
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

As an example:

[wpv-conditional if="( '[wpv-search-term param="my_term"]' ne '' )"]
  TEST
[/wpv-conditional]

The above sample code will output TEST only if the my_term URL parameter is not empty.
It works everywhere, as long Views is active.

Even if you pass no parameter at all, it still works great.

Let me know how that works for you, I use it a lot, and it's quite powerful.

#556832

With this shortcode

[wpv-conditional if="( '[wpv-search-term param="id_demande"]' ne '' )"]
  <a href="[wpv-post-url id='[wpv-post-param var='id_demande']']">truc</a>
[/wpv-conditional]

When the "id_demande" url parameter is set (even if empty), it's OK, but if it is not set (not in the url), then I got "Undefined index: id_demande"

#556833

My mistake, replacing [wpv-post-param var='id_demande'] by [wpv-search term param='id_demande'] worked great.
Thank you.