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
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
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
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
Thank you - this is perfect!
/Lisbeth