Skip to:
Content
Pages
Categories
Search
Top
Bottom

Trying to echo User role in all posts

Viewing 4 replies - 1 through 4 (of 4 total)

  • dtabraham
    Participant

    @dtabraham

    I see I have accidentally posted this inside the Installing Buddypress category.
    My apologies,; I didn’t expect that to happen when I clicked on New Topic.

    Is there a way for me to move it?


    noizeburger
    Participant

    @noizeburger

    @dtabraham
    I’m looking for the same functionality and would prefer, to pass the user role over to a custom xprofile field to integrate it in buddypress search.
    Meanwhile I show the user roles with a function I found in the forums:

    bp-custom.php:

    function pc_get_userrole ($user_id) {
    
    $user = new WP_User($user_id);
    
    $userclean = $user->roles[0];
    
    return $userclean;
    
    }
    
    function get_user_role( $user_id ){
    
      $user_data = get_userdata( $user_id );
    
      if(!empty( $user_data->roles ))
          return $user_data->roles[0];
    
      return false; 
    
    }

    and then echo where you want (in my case I did it in member-header.php):

    <?php echo get_user_role(bp_displayed_user_id()); ?>

    You can take a look here: link to a profile on my site

    greetings


    noizeburger
    Participant

    @noizeburger

    To show it in your members-list maybe you have to echo with <?php echo pc_get_userrole(bp_current_user_id()); ?>

    Not sure


    dtabraham
    Participant

    @dtabraham

    @noizeburger Thanks! Seems like it could work, but do you have any idea if it can work within a loop? Struggling a little with getting it to display for Activity posts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Trying to echo User role in all posts’ is closed to new replies.
Skip to toolbar