Skip to:
Content
Pages
Categories
Search
Top
Bottom

List groups i am admin of

  • @mattsten

    Participant

    I would like to find out if there is a way in buddypress to list the groups that i am admin of on the front end. If i click my groups it shows all the groups that i belong to, which is great but i belong to hundreds. I cant find a way to show a list of groups that i am admin of.

Viewing 10 replies - 1 through 10 (of 10 total)
  • @henrywright

    Moderator

    If you just need a quick and dirty approach for yourself to view, you could use the standard group loop to output a loop. See here.

    Then put the following snippet directly after the line: <?php while ( bp_groups() ) : bp_the_group(); ?>

    Snippet:

    <?php
    $args = array(
        'populate_extras' => true,
        'group_id => bp_get_group_id()
    );
    $group = groups_get_group( $args );
    
    if ( ! in_array( bp_loggedin_user_id(), $group->admins ) ) {
        continue;
    }
    ?>

    Notes:

    • I haven’t tested
    • This approach won’t be performant
    • I haven’t considered pagination

    That said, it should get the job done. The alternative is to write some SQL and use the wpdb class.

    @shanebp

    Moderator

    There is a BP function for getting the ids of the groups for which you’re an admin: get_is_admin_of

    You could use it like this:

    function my_group_admin_ids() {
    	
        $my_group_ids = BP_Groups_Member::get_is_admin_of( 1 ); //if your id = 1
    	
        foreach( $my_group_ids['groups'] as $group ) {
    	
    	$link = bp_get_group_permalink( $group );
    	
    	echo '<a href="' . $link .'">' . $group->name . '</a><br/>';
    	
        }
    }
    add_action( 'bp_before_directory_groups', 'my_group_admin_ids');

    If you want to create a custom tab to hold that info, you need to create a new li element in a template overload of this file:
    \bp-templates\bp-legacy\buddypress\groups\index.php

    @mattsten

    Participant

    Thanks for the help ill try these

    @henrywright

    Moderator

    @mattsten don’t bother with my solution; @shanebp’s is far better!

    @alvin341965

    Participant

    I want this too.
    on my profile i only wanna see my groups where i am admin of and not all of them i am member of!

    what file(s) should I edit?
    i run the latest version of BP and WP.

    kind regards

    @henrywright

    Moderator

    Just put @shanebp’s code in your theme’s functions.php file.

    @alvin341965

    Participant

    thank you that works.
    But i need something else to work on my profile page.

    when you click groups on profile tab i want only my own groups that i created to show and not the ones that i am a member of. Where do i put the filter in php

    Example my own groups on profile page

    kind regards

    @henrywright

    Moderator

    @alvin341965 That’s quite different so you should open a different topic for that 🙂

    @alvin341965

    Participant

    ok sorry for that…
    new to this forum 🙁
    will create a new topic

    thank you

    @henrywright

    Moderator

    No worries; welcome to the forum! 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘List groups i am admin of’ is closed to new replies.
Skip to toolbar