Skip to:
Content
Pages
Categories
Search
Top
Bottom

List groups i am admin of


  • mattsten
    Participant

    @mattsten

    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)

  • Henry Wright
    Moderator

    @henrywright

    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

    @shanebp

    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

    @mattsten

    Thanks for the help ill try these


    Henry Wright
    Moderator

    @henrywright

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


    Alvin341965
    Participant

    @alvin341965

    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


    Henry Wright
    Moderator

    @henrywright

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


    Alvin341965
    Participant

    @alvin341965

    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


    Henry Wright
    Moderator

    @henrywright

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


    Alvin341965
    Participant

    @alvin341965

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

    thank you


    Henry Wright
    Moderator

    @henrywright

    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