Skip to:
Content
Pages
Categories
Search
Top
Bottom

Pull Learndash group leader information via shortcode


  • Sergio Peña
    Participant

    @nexministry

    Hello!

    I am desperately trying to pull the group leader/admin of a learndash group into a page.
    Screenshots: http://prnt.sc/e5g1kg, http://prnt.sc/e5g1ln, http://prnt.sc/e5g1mn

    Unfortunately, I’m not a coder so I’ve been reading through the wordpress codex and whatever I can find from Learndash and Buddypress. Since learndash and buddypress can sync groups, the group leader becomes group administrator.

    I’ve read this: https://buddypress.org/support/topic/showing-group-admin-in-loop/
    and have copy/pasted the code, changed the code, but no luck. It’s all Greek to me 🙁

    I can get it to spit out the current user’s id via the get_current_user_id() function, but can’t figure out how to get the group id from current user id. And this talk of loops is even more confusing.

    Please help!

    Wordpress: 4.7.2
    Buddypress: 2.7.4
    Learndash: 2.3.3

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

  • Sergio Peña
    Participant

    @nexministry

    Any one available? Or should I post this in another section?


    shanebp
    Moderator

    @shanebp

    Try using bp_get_group_id().
    If you can get the group id, then use groups_get_group_admins( $group_id ) to get the group admins.
    Pull out the user ids of the group admins and use the ids to get the user data that you want.

    NOTE: you should be asking LearnDash these questions.
    By asking them here, you are asking volunteers to answer questions about a third-party premium plugin.
    Therefore, you most likely won’t get much assistance here.


    Sergio Peña
    Participant

    @nexministry

    Thank you for your response.

    I did ask Learndash and they referred me to third party programmers.

    Since I am using buddypress groups, I thought it was appropriate to ask here as well. Apologies if I was mistaken!

    So would it be something like this:

    add_shortcode('course_mentor','nex_course_mentor');
    function nex_course_mentor($atts, $content = null){
      if(!is_user_logged_in())
        return;
      if(!bp_is_active('groups'))
        return;
    
      $nex_group_id  = bp_get_group_id(get_current_user_id());
    
      if(!empty($nex_group_id)){
        foreach($nex_group_id as $nex_group_id){
          $nex_admins = groups_get_group_admins( $nex_group_id );
          foreach($admins as $admin){
            ?>
            <a href="<?php echo bp_core_get_user_domain($admin->user_id) ?>"
            title="<?php echo bp_core_get_user_displayname( $admin->user_id, true ) ?>">
            <?php echo  bp_core_fetch_avatar ( array( 'item_id' => $admin->user_id, 'type' => 'thumb' ) ) ?></a>';
      <?php
          }
        }
      }
    }

    I’m just copy/pasting and trying to connect a bunch of different answers together. As you can tell, I’m no coder.

    Since each group may have more than one group leader/mentor I had a loop in there. Hopefully that will get the ball rolling on what I’m trying to do.

    Am I on the right track?


    shanebp
    Moderator

    @shanebp

    >Am I on the right track?

    This is wrong. bp_get_group_id(get_current_user_id());
    Look up that function to see how it is used.

    Ask LearnDash how to get the group id on the LearnDash screen that you want to use.


    Sergio Peña
    Participant

    @nexministry

    Here’s the code for anyone who wants to do the same:

    
    add_shortcode('course_mentor','group_course_mentor');
    
    function group_course_mentor($atts, $content = null){
      if(!is_user_logged_in())
        return;
      if(!bp_is_active('groups'))
        return;
      global $wpdb,$bp;
        $batches = groups_get_user_groups(get_current_user_id());
    $return = '';
      if(!empty($batches['groups'] )){
        foreach($batches['groups'] as $batch){
          $admins = groups_get_group_admins( $batch );
          foreach($admins as $admin){
            $return .=  '<a href="'.bp_core_get_user_domain($admin->user_id).'" title="'. bp_core_get_user_displayname( $admin->user_id, true ) .'">'.bp_core_fetch_avatar ( array( 'item_id' => $admin->user_id, 'type' => 'thumb' ) ) .'</a>';
          }
        }
      }
      return  $return ;
    }
    

    Credit goes to Alex @ WPLMS for this 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar