Problem:
How to display content based on the User Role of the Post Author?
Solution:
1. Please add following code in your theme’s or child theme’s functions.php file:
function get_author_role() { global $authordata; $author_roles = $authordata->roles; $author_role = array_shift($author_roles); return $author_role; } add_shortcode( 'user_role_func', 'get_author_role' );
2. Register the ‘'user_role_func'’ shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments. Screenshot here: https://d7j863fr5jhrr.cloudfront.net/wp-content/uploads/2017/06/543582-Register_Custom_Shortcode.png?x36781
3. Then use shortcode in conditional output something like this, you can add it in your View or Content Template:
[wpv-conditional if="( '[user_role_func]' eq 'contributor' )"] contributor content goes here [/wpv-conditional]
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 |
---|---|---|---|---|---|---|
- | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | - |
- | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
This topic contains 2 replies, has 2 voices.
Last updated by David 6 years, 9 months ago.
Assisted by: Noman.