Skip Navigation

[Resolved] Display custom user field conditionally

This support ticket is created 3 years, 10 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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by matthiasK-3 3 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1963309

I created several custom user fields that I want to show at a page only if those are not empty. As I can't find custom user fields in the drop down list of the Conditional block I am using the advanced editor.

It works fine as long as the custom user field is a single line text field. But for the field type 'telephone' I do not succeed. I am using the following code:
[wpv-conditional if=" NOT ( empty( [types usermeta='festnetz' current_user='true'][/types]) ) " ]<br>Tel. [types usermeta='festnetz' current_user='true'][/types][/wpv-conditional]
where 'festnetz' contains a phone number. It returns null independant wether the test is against Empty or Not Empty.

I need help on the proper code.

Thanks

#1963597

Hi,

Thank you for contacting us and I'd be happy to assist.

I've tested the conditional code that you've shared on my test website and it works as expected.

Can you please make sure that the user field slug that you're using is correct?

In case the issue still persists, you're welcome to share temporary admin login details along with the page where this conditional block is in use.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1966223

Thank you for sharing these details.

The "empty" conditional check is failing in this case because the phone field contains numbers with spaces.

In such cases, it would be better to change the empty check from:


[wpv-conditional if=" NOT ( empty( [types usermeta='festnetz' current_user='true'][/types]) ) " ]
<br>Tel. [types usermeta='festnetz' current_user='true'][/types]
[/wpv-conditional]

To:


[wpv-conditional if="( '[types usermeta='festnetz' current_user='true'][/types]' ne '' )"]
<br>Tel. [types usermeta='festnetz' current_user='true'][/types]
[/wpv-conditional]

Related guide:
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

#1966435

It's so easy when you know where to look! Thanks for the help!