Skip Navigation

[Resolved] conditional output based on url parameter

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by lisbethW 8 years, 4 months ago.

Assisted by: Eduard.

Author
Posts
#356059

I have a cred form (placed on a page) that creates a child post of a CPT (course-date) via a url parameter (parent_course-date_id)
On the page I display a view with info from the course-date using the url parameter. But if the page is accessed without a url parameter added, it shows info from a random course date.

I am trying to: find a way to make a conditional output that only shows the info, if there is a parent_course-date_id in the url.

I visited this URL: https://toolset.com/forums/topic/how-to-use-a-conditional-based-on-a-query-parameter/ that deals with something similar and https://toolset.com/documentation/views-shortcodes/#wpv-search-term but didn't find a solution.

Can you help?

Thanks, Lisbeth

#356118

Hi,

Additionally you can take a look to this topic:
https://toolset.com/forums/topic/conditional-output-using-url-parameter/

Please let me know if this resolves your issue.

Thanks

#356260

Hi Eduard,

Thank you for your suggestion - it seems to be exactly what I need.
But I can't make it work...

I inserted this in my content template

--- test af conditional
[wpv-if evaluate="'[wpv-post-param var="parent_course-date_id"]'!=''"] - der er et parent_course-date_id[/wpv-if]
---

and even though the url looks like this hidden link
it only returns
— test af conditional —

on the page, where I expected to see
— test af conditional - der er et parent_course-date_id —

/Lisbeth

#356285

Sorry , missed one more link in my previous comment.
You have to add wpv-post-param shortcode code in your functions.php like this:
[php]
add_shortcode( 'wpv-post-param', 'wpv_post_param_shortcode' );
function wpv_post_param_shortcode( $atts ) {
if ( ! empty( $atts['var'] ) ) {
if( isset( $_GET[ $atts['var'] ] ) ) {
$var = (array) $_GET[ $atts['var'] ];
return esc_html( implode( ', ', $var ) );
} else {
return '';
}
}
}
</code

https://toolset.com/forums/topic/how-can-my-view-access-a-url-parameter-in-a-query-string/#post-190780

Please let me know if this resolves your issue.

Thanks

#356288

Thank you - this is perfect!
/Lisbeth

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