Skip Navigation

[Resolved] Conditional output if wpv-post-author is a administrator

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

Problem:

I'm creating a directory where info on each profile is different if the author of the listing have a specific role. To make it simple, this is a short exemple. If the author of this listing is an administrator, show "This author is an administrator of the site".

Solution:

There isn't "info" attribute in shortcode [wpv-post-author], see our document:

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

In your case, you can setup a custom shortcode to get user role of post author, then use it as condition of shortcode [wpv-conditional] , see similar thread here:

https://toolset.com/forums/topic/conditional-display-based-on-user-role-of-post-author/#post-543582

Relevant Documentation:

This support ticket is created 5 years, 8 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 jean-francoisB 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1214530

Hi,

I'm creating a directory where info on each profile is different if the author of the listing have a specific role. To make it simple, this is a short exemple. If the author of this listing is an administrator, show "This author is an administrator of the site".

I tried this code and doesn't seems to work. Do you have any suggestion to make it work?

[wpv-conditional if="( '[wpv-post-author info="role"]' eq 'administrator' )"]
This author is an administrator of the site
[/wpv-conditional]

Thank you very much!

Jeff

#1214560

Dear Jeff,

There isn't "info" attribute in shortcode [wpv-post-author], see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author

In your case, you can setup a custom shortcode to get user role of post author, then use it as condition of shortcode [wpv-conditional] , see similar thread here:
https://toolset.com/forums/topic/conditional-display-based-on-user-role-of-post-author/#post-543582

#1214611

Wow, straight to the point! I would not have thought that we should create a function to make this happen. Instead of adding a function to my theme, I installed a plugin named "My Custom Functions" and put the function there. Did the job like a charm!