Skip Navigation

[Resolved] Conditions that check for a user field

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

Problem:

The issue here is that the user wanted to conditionally display a user's field based on their previous field selection.

Solution:

This can be done by using our views conditional statement.

An example of this can be seen below.

[wpv-conditional if="( '[types usermeta='user_phone' user_is_author='true'][/types]' eq 'public' )"]
 
Content goes here
 
[/wpv-conditional]

Relevant Documentation:

This support ticket is created 4 years, 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by marcialB 4 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#1367711

Hi there

We have a user field for the phone number. We display that phone number on each post, a user publishes.
[types usermeta='user_phone' user_is_author='true'][/types]
But we want to let users decide if they want their phone number to be public or not. I created a checkbox for the users.
I can let the result display with this shortcode: [types usermeta='user_phone_privacy' user_is_author='true'][/types]
I have set it to save "public" to the database if checked, and "0" if it's not selected.

However, I struggle to get the condition to work. I currently have it like this:
[wpv-conditional if="($(wpcf-user_phone_privacy) eq 'public' )"]
[types usermeta='user_phone' user_is_author='true'][/types]
[/wpv-conditional]
However, I don't tell the condition to check in the authors' fields, therefore it doesn't work. How can I do that?

I tried to follow this thread but didn't quite get it: https://toolset.com/forums/topic/conditionally-display-html-only-if-the-user-created-and-owns-a-custom-post-type/

Thanks for your help.

Best,
Marcial

#1368179

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Marcial,

Thank you for getting in touch.

I believe you should write the conditional like this.


[wpv-conditional if="( '[types usermeta='user_phone' user_is_author='true'][/types]' eq 'public' )"]

Content goes here

[/wpv-conditional]

Please try this and let me know if it helps.

Thanks,
Shane

#1368405

Hi Shane

Thanks a lot! I didn't know that I could use this shortcode for the conditions. That's great.

Best,
Marcial

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