Skip Navigation

[Resolved] Using a single value from usermeta that has multiple values

This support ticket is created 4 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by MichaelR9215 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1485721

Hello,

I am trying to use usermeta that has multiple values that are submitted via checkboxes, but cannot get a single value to display.

My ideal usage is actually for a larger project of creating a staff portal.

I created a new user type called Staff, and a new custum user field for "employee type". There are 5 types of employees, and I want to be able to create a conditional statement that gives access to certain content based on the employee type.

I tried multiple ways of making this work, but I can't seem to drill into the usermeta data to grab a single value from the array.

1...[wpv-user field="wpcf-portal-staff-type" separator=", " index="0"] ... this displays the entire array.

2...[wpv-user field="wpcf-portal-staff-type" separator=", " index="1"] ... this displays the entire array.

3...[wpv-user field="wpcf-fields-checkboxes-option-1bc875802f7cd80318e2856c04d94805-1" separator=", "] ... this displays nothing.

4...[types usermeta="wpcf-portal-staff-type" separator=", " index="0"][/types] ... this displays nothing.

5...[types usermeta="portal-staff-type" separator=", " index="0"][/types] ... this displays nothing.

6...[types usermeta="wpcf-portal-staff-type" separator=", "][/types] ... this displays nothing.

If you have a suggestion on a better way to approach this, I would appreciate it.

Also, for your information, I will be allowing the managers/admins to create content within this website, and would love it if they had control over the content access, so when they created a new page or post, they would be able to wrap the content in a specific shortcode that locked the content down based on that employee type usermeta and how the current user's usermeta matches.

I hope this makes sense.

Thanks!

#1486027

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please try to use the following shortcode and try to resolve your issue:

[types usermeta='portal-staff-type' output='raw' index='0' user_is_author='true'][/types]

More info:
=> https://toolset.com/documentation/user-guides/custom-content/repeating-fields/

#1486997

I'm sorry Minesh, this shortcode didn't work. Would there be a reason why?

Please advise.

#1487943

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'm not sure yet where exactly you added the shortcode.

Can I have a problem URL where you added the shortcode as well as admin access details?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1491475

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - so the thing is that, as you are using the checkboxes field, you need to use the attribute "option" instead of "index" to target the specific checkbox option.

There are two ways to display conditional content based on the checkbox.
- Using attribute "state" to know checkbox is checked or unchecked and targetting a specific checkbox option.
For example:

[types usermeta='portal-staff-type' option='0' user_current='true' state='checked']
Option 0 (all-staff) is checked - add your content here for checked state
[/types]

[types usermeta='portal-staff-type' option='0' user_current='true' state='unchecked']
Option 0 (all-staff) is unchecked - add your content here  when option 0 is NOT checked
[/types]

[types usermeta='portal-staff-type' option='1' user_current='true' state='checked']
Option 1 (admin) is checked - add your content here for checked state
[/types]

[types usermeta='portal-staff-type' option='1' user_current='true' state='unchecked']
Option 1 (admin) is unchecked - add your content here  when option 1 is NOT checked
[/types]

And, Another way is to use the [wpv-conditional] shortcode.
For example:

[wpv-conditional if="( '[types usermeta='portal-staff-type' output='raw' option='0' user_current='true'][/types]' eq 'all-staff' )"]
  // add your content here when checkbox option  all-staff is checked.
[/wpv-conditional]

[wpv-conditional if="( '[types usermeta='portal-staff-type' output='raw' option='0' user_current='true'][/types]' eq '' )"]
  // add your content here when checkbox option  all-staff is unchecked.
[/wpv-conditional]

More info;
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes
=> https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

#1492819

My issue is resolved now. Thank you!