Passer la navigation

[Résolu] I have a problem with conditionals using user fields.

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 4 years, 3 months. 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 -

Fuseau horaire du supporter : Asia/Hong_Kong (GMT+08:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par henriqueD Il y a 4 years, 3 months.

Assisté par: Luo Yang.

Auteur
Publications
#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!