Skip Navigation

[Gelöst] Conditions that check for a user field

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 5 Jahren, 1 Monat. 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 – 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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von marcialB vor 5 Jahren, 1 Monat.

Assistiert von: Shane.

Author
Artikel
#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

Sprachen: Englisch (English )

Zeitzone: 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