Skip Navigation

[Resolved] Filtering view output based on URL parameter

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

Problem:

Display different result depends on URL parameter value.

Solution:

You can use shortcode [wpv-search-term param="staffmember"] to get the URL parameter "staffmember" value, and check it with [wpv-conditional] shortcode, then display what you want, for example:

https://toolset.com/forums/topic/filtering-view-output-based-on-url-parameter/#post-1493081

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-search-term

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-conditional

This support ticket is created 4 years, 2 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.01 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 2 replies, has 2 voices.

Last updated by geophray 4 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1492835

Tell us what you are trying to do?
I'm attempting to display the value of a custom field from a related CPT post at the top of a cred form as filtered by the post id in a URL parameter. When the parameter is set, it works beautifully, but I'd like for it to display "us" instead of the name that is contained in the custom field if the parameter is not set. I though I could accomplish this with a view that is filtered by URL parameter, but instead of it returning no results and the default content for an empty query, it is showing all results. Is there an easier way to achieve this?

Is there any documentation that you are following?
No

Is there a similar example that we can see?
hidden link

Try removing the URL parameter from that link to see that all results are being inserted.

u/n: rodlimb
p/w: communicating-love

#1493081

Hello,

You can use shortcode [wpv-search-term param="staffmember"] to get the URL parameter "staffmember" value, and check it with [wpv-conditional] shortcode, then display what you want, for example:

[wpv-conditional if=" ( '[wpv-search-term param="staffmember"]' eq '') "] Us [/wpv-conditional]

[wpv-conditional if=" ( '[wpv-search-term param="staffmember"]' eq '') " evaluate="false"] Display your post view here ....  [/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-search-term
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-conditional

#1494991

Thank you so much Luo! That was a simple fix! Working as expected now!

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