Skip Navigation

[Resolved] Conditional Display Based on Custom User Field

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

Problem:
How to dispaly conditional content based on custom user field.

Solution:
To dispaly the conditional output based on custom user field you need to use [wpv-conditional] shortcode with [types usermeta='metaname'][/types] shortcode.

You can find the proposed solution with the reply at here

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

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
- 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 2 replies, has 2 voices.

Last updated by julieP 7 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#552908

I created a custom User field wpcf-custom-user-field

I'm trying to display content only if the value of this custom user field isn't empty.

I visited this page:-

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

and from that created this conditional statement:-

[wpv-conditional if="( '[types usermeta="wpcf-custom-user-field"]' ne '' )"]Custom User Field Contains A Value[/wpv-conditional]

but the text isn't displayed. I've checked the database and the field contains a value for the current user.

Not sure why it's not working. Can you advise please?

Thanks

#552980

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - when you use [types] shortcode you do not need to prefix custom field name with 'wpcf-'.

For example:

[wpv-conditional if="( '[types usermeta="user-bio"][/types]' ne '' )"]

Custom User Field Contains A Value

[/wpv-conditional]
#553051

Hi Minesh

I tired that but it still didn't work. However I noticed I had omitted to close the shortcode with [/types] - once I added that, the output appears.

Many thanks for your help