Skip Navigation

[Resolved] Use a conditional statement to show content if a field contains the current user

This support ticket is created 4 years, 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 4 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1727633

Tell us what you are trying to do?

Use a conditional statement to show content if a field contains the current user id. I've been testing to the wpv_contains functions found in support that doesn't seem to be responding.

Is there any documentation that you are following?

https://toolset.com/forums/topic/conditional-display-of-content-condition-not-equal-but-contains-4/
https://toolset.com/forums/topic/display-field-if-it-contains-a-given-string/

Is there a similar example that we can see?

I'm currently using the code from the article above which lead me to add a shortcode to the functions.php

// Add Shortcode
function wpv_contains( $atts ) {

// Attributes
$atts = shortcode_atts(
array(
'haystack' => '',
'needle' => '',
),
$atts
);

$pos = strpos($atts['haystack'], $atts['needle']);
if($pos !== true){
return false;
}

}
add_shortcode( 'wpv_contains', 'wpv_contains' );

Then on the test page I'm testing the shortcode with
[wpv-conditional if="( '[wpv_contains haystack='testing' needle='test']' ne 'false' )"]
test output[/wpv-conditional]
[wpv-conditional if="( '[wpv_contains haystack='testing' needle='test']' ne '0' )"]
test output[/wpv-conditional]
[wpv-conditional if="( '[wpv_contains haystack='testing' needle='test']' ne '1' )"]
test output[/wpv-conditional]
[wpv-conditional if="( '[wpv_contains haystack='testing' needle='test']' ne 'true' )"]
test output[/wpv-conditional]

I get nothing as a result of any of these.

What is the link to your site?

hidden link <- This page has the shortcodes on it.

#1727821

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - view's offers the conditional shortcode [wpv-conditional] and with that we offer the CONTAINS() function to test if string contains the part of the string you pass or not.

For example:

[wpv-conditional if="( CONTAINS(#(foreign-language),'chinese') )"]
<p>This consultant speaks Chinese!</p>
[/wpv-conditional]

- Wherer #(foreign-language) is a taxonomy slug passed to CONTAINS() function.

You can customise the conditional statement as per your requirement.

More info:
=> https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific