Skip Navigation

[Resolved] Split: Toolset Maps and ultimate members – display conditional output based on user role in user view loop

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 2 replies, has 2 voices.

Last updated by Arne 4 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1441933

Hi Minesh,

Can I use a different marker on the map by user role?

Thank you for your help!
Arne

#1441937

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes - you can display the different markers based on the current user role in the user type view's loop using the [wpv-conditional] shortcode.

You should try to add the following code to your current theme's functions.php file
OR
"Custom code" section offered by Toolset:
=>

function func_get_current_user_role_in_loop( $atts ) {
  $a = shortcode_atts( array(
      'user_id' => ''
  ), $atts );
  $userdata = get_user_by('ID', $a['user_id']);
  $user_roles = $userdata->roles;
  $user_role = array_shift($user_roles);
  return $user_role;
}
add_shortcode( 'get_user_role_in_loop ', 'func_get_current_user_role_in_loop' );

Then in your View, use the shortcode in a conditional like this:

[wpv-conditional if="( '[get_user_role_in_loop  user_id='[wpv-user field='ID']']' eq 'editor' )"]
  display your marker here for editor role
[/wpv-conditional]
[wpv-conditional if="( '[get_user_role_in_loop  user_id='[wpv-user field='ID']']' eq 'administrator' )"]
   display your marker here for administrator role
[/wpv-conditional]

Where;
=> Do not forget to register "get_user_role_in_loop" shortcode at:
- Toolset > Settings > Frontend Content > Third party shortcode arguments.

More info:
=> https://toolset.com/documentation/user-guides/views/shortcodes-within-shortcodes/#third-party-shortcode-arguments

#1444245

My issue is resolved now. Thank you!