Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get all groups in admin side


  • Oxibug
    Participant

    @oxibug

    Hi There!

    I don’t know why it’s very complicated to get groups, Anyway I need to make a dropdownlist so I need GroupID => Group Name pair.

    I tried to get all groups in Admin pages but it failed because of those errors
    [Undefined property: BP_Groups_Component::$table_name]
    [Undefined property: BP_Groups_Component::$table_name_groupmeta]

    — Code 1

            return BP_Groups_Group::get( array(
                
                'type'               => null,
                'orderby'            => 'date_created',
                'order'              => 'DESC',
                'per_page'           => null,
                'page'               => null,
                'user_id'            => 0,
                'slug'               => array(),
                'search_terms'       => false,
                'search_columns'     => array(),
                'group_type'         => '',
                'group_type__in'     => '',
                'group_type__not_in' => '',
                'meta_query'         => false,
                'include'            => false,
                'parent_id'          => null,
                'update_meta_cache'  => true,
                'update_admin_cache' => false,
                'exclude'            => false,
                'show_hidden'        => false,
                'status'             => array(),
                'fields'             => 'all',
                
            ) );

    — Another one

    if( bp_has_groups() ) {
                
                while( bp_groups() ):
    
                    bp_the_group();
    
                    return array(
                      
                        'id'    => bp_get_group_id(),
                        'title' => bp_get_group_name(),
                        'type'  => bp_get_group_type(),
                        'members'   => bp_get_group_member_count()
                        
                    );
    
                endwhile;
                
            }
Viewing 2 replies - 1 through 2 (of 2 total)

  • shanebp
    Moderator

    @shanebp

    Use the bp_ready hook.
    In your function, use groups_get_groups.
    Review the arguments in that function in bp-groups/bp-groups-functions.php


    Oxibug
    Participant

    @oxibug

    Thanks Pal, Working GREAT

    I was using bp_include like suggested in documentation but it seems it’s related to files only.

    Final Code

    class MY_PLUGIN_BuddyPress {
    
        private static $_instance = null;
        
        /*
         * Silent Constructor
         *
         * */
        public function __construct() { }
    
        public static function instance() {
    
            if( is_null( self::$_instance ) ) {
    
                self::$_instance = new self;
    
                self::$_instance->init();
    
            }
    
            return self::$_instance;
    
        }
    
        private function init() {
                
            add_action( 'bp_load', array( &$this, '_buddypress_action' ), 10 );
            
        }
    
        public function _buddypress_action() {
                
            $all_groups = BP_Groups_Group::get( array(
                
                'type'               => null,
                'orderby'            => 'date_created',
                'order'              => 'DESC',
                'per_page'           => null,
                'page'               => null,
                'user_id'            => 0,
                'slug'               => array(),
                'search_terms'       => false,
                'search_columns'     => array(),
                'group_type'         => '',
                'group_type__in'     => '',
                'group_type__not_in' => '',
                'meta_query'         => false,
                'include'            => false,
                'parent_id'          => null,
                'update_meta_cache'  => true,
                'update_admin_cache' => false,
                'exclude'            => false,
                'show_hidden'        => false,
                'status'             => array(),
                'fields'             => 'all',
                
            ) );
    
        }
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar