Skip Navigation

[Resolved] Wanted to show custom fields in a custom post conditionally based on a user role

This support ticket is created 3 years, 7 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 – 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)

This topic contains 1 reply, has 2 voices.

Last updated by Shane 3 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#2067787

Hi,

I have a custom post with a large number of custom fields. Some of this information is confidential and only meant for employees (who will be tagged with a specific custom role on toolset), while the other information can be shared with the public.

When a website visitor views this custom post, I want it to not show up the fields meant for employees. However, when employees log in, they should be able to see this content.

What is the best way to implement the same.

Best Regards,
Ashi.

#2068275

Shane
Supporter

Languages: English (English )

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

Screenshot 2021-05-25 at 4.21.56 PM.png

Hi Ashi,

Thank you for getting in touch.

Are you using the Gutenburg Editor ? If so then you can use the conditional block and then place the custom fields that you want to be hidden inside this conditional block. See Screenshot

If are not using the gutenburg editor then you can use the conditional shortcode below.

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' )"]

Some Content goes here
[/wpv-conditional]

Ofcourse you will change administrator to the slug of the role that you want to see the fields and then add your custom field shortcodes within the conditional.

Thanks,
Shane