Skip Navigation

[Resolved] conditional output in a view

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

Problem:

Us wpv-conditional shortcode to compare custom user field.

The information that I am looking for is in the wp_usermeta table. The condition would be something like, if meta_value eq 4 where user_id eq current user and meta_key eq "wpcf-privacy-level"

Solution:

You can get the current logged-in user's field "wpcf-privacy-level" value with shortcode:
[wpv-user field="wpcf-privacy-level"]

and use above shortcode in conditional, for example:

( '[wpv-user field="wpcf-privacy-level"]' eq '4' ) 

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-user

This support ticket is created 4 years, 9 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 jonathanR-5 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1552795
Screen Shot 2020-03-16 at 2.26.38 PM.png
Screen Shot 2020-03-16 at 12.52.44 PM.png

Tell us what you are trying to do?

I'm working in a multisite WP setting.

I have a user form with custom fields so that registered users can edit their own information. I would like to have a conditional output in a view that filters by one of the custom fields.

Specifically, one of my custom user fields is "privacy". There are different levels of privacy that would allow various amounts of user information to be displayed on my site. (eg 1=everything visible, 4=no information visible)

I'm not sure how to go about this, but what I am thinking is to use a custom conditional output to filter out pieces of information depending on the "privacy" setting for each user.

The information that I am looking for is in the wp_usermeta table. The condition would be something like, if meta_value eq 4 where user_id eq current user and meta_key eq "wpcf-privacy-level"

Is there a syntax for this sort of custom conditional output that I could use?

Or, am I doing this in a overly complicated way, in which case can you suggest a better way to accomplish my goal?

#1553095

Hello,

You can get the current logged-in user's field "wpcf-privacy-level" value with shortcode:
[wpv-user field="wpcf-privacy-level"]
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-user

and use above shortcode in conditional, for example:

   ( '[wpv-user field="wpcf-privacy-level"]' eq '4' ) 
#1553705

My issue is resolved now. Thank you!