Skip Navigation

[Resolved] I have a problem with conditionals using user fields.

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

Problem:

How to use custom user field in [wpv-conditional] shortcode?

Solution:

Here is an example:

https://toolset.com/forums/topic/i-have-a-problem-with-conditionals-using-user-fields/#post-2063823

Relevant Documentation:

This support ticket is created 2 years, 11 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
- 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 henriqueD 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2063421

Hello, how are you?

I have a problem with conditionals using user fields.

if you look below, only one condition works, the others do not. all fields are plain text, except date, which is the same date.

can you help me?

<!-- Test -->
[wpv-conditional if="( [types usermeta='cu-nome-completo'][/types] ne '' )"]
<p>cu-nome-completo</p>
[/wpv-conditional]

[wpv-conditional if="( [types usermeta='cu-data-de-nascimento'][/types] ne '' )"]
<p>cu-data-de-nascimento</p>
[/wpv-conditional]

[wpv-conditional if="( [types usermeta='cu-ramal'][/types] ne '' )"]
<p>cu-ramal</p>
[/wpv-conditional]

[wpv-conditional if="( [types usermeta='cu-setor'][/types] ne '' )"]
<p>cu-setor</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-cu-nome-completo) ne '' )"]
<p>cu-nome-completo</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-cu-data-de-nascimento) ne '' )"]
<p>cu-data-de-nascimento</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-cu-ramal) ne '' )"]
<p>cu-ramal</p> <!-- Test -->work fine<!-- /Test -->
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-cu-setor) ne '' )"]
<p>cu-setor</p>
[/wpv-conditional]
<!-- /Test -->

I'm waiting

thanks

#2063823

Hello,

The dollar($) character works for post field, it won't work for user field, so you need to use shortcode to render the custom user field.

In order to use shortcodes within wpv-conditional shortcode as condition, you need to wrap those shortcodes into single quotes, and you need to avoid to use single quote in those shortcodes, so you can use double quotes in those shortcodes, for example:

[wpv-conditional if="( '[types usermeta="my-user-field"][/types]' ne '' )"]
my-user-field has value
[/wpv-conditional]
#2064139

My issue is resolved now. Thank you!

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