Skip to:
Content
Pages
Categories
Search
Top
Bottom

display groups members list (in all groups)


  • diegomiguel05
    Participant

    @diegomiguel05

    Hello, I’d like to ask some help, please.

    I need that any user of my site could access the others groups home pages (even others private groups which the user don’t belong to) and access the members lists of any group. Does anybody know any hook or any other way?

    Thanks in advance.

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

  • shanebp
    Moderator

    @shanebp

    Where and when you place the data is up to you.
    To gather the data, try :

    $args = array(
    	 'show_hidden'   => true,
    	 'per_page'      => -1      
    );
    
    $groups = groups_get_groups( $args );
    
    foreach ( $groups['groups'] as $group ) {
    			
    	$args = array(
    		'group_id'   		=> $group->id,
    		'exclude_admins_mods'   => false      
    	);
    
    	$members = groups_get_group_members( $args ); 
    	
    	echo'<pre>'; var_dump( $members );  echo'</pre>'; // just for reference
    	
    	// do something with the member data
    }

    diegomiguel05
    Participant

    @diegomiguel05

    Hello shanebp, thank you very much for your response:

    We have realized that users could not access the home page of other private groups due to the inteference of another active plugin. Deactivating it, users already have access to the home page of others private groups, but still can not see the list of members of those groups. I’ve been trying to use your code (in function.php and writing it as html text), but it does not work, possibly I’m not writing it in the right place. Do you know how to solve this problem, please??

    Thank you very much for your help.


    diegomiguel05
    Participant

    @diegomiguel05

    Hello @shanebp, thanks for the hook.

    Sorry but I don`t know where I have to insert it. Wherever I paste it, no group members list is displayed (probably I’m not pasting it it in the correct file), I have tried in functions.php and in group-header.php of the theme. Could you please tell me where I should insert it?

    Thank you and sorry for bothering.


    shanebp
    Moderator

    @shanebp

    As stated, the code is just an example of collecting the groups and group members.

    You could put the code in a function and then call that function wherever you want.
    For example, this could go in your theme > functions.php file :

    function diego_show_groups() {
    
    	$args = array(
    		 'show_hidden'   => true,
    		 'per_page'      => -1      
    	);
    
    	$groups = groups_get_groups( $args );
    
    	foreach ( $groups['groups'] as $group ) {
    				
    		$args = array(
    			'group_id'   		=> $group->id,
    			'exclude_admins_mods'   => false      
    		);
    
    		$members = groups_get_group_members( $args ); 
    		
    		echo'<pre>'; var_dump( $members );  echo'</pre>'; // just for reference
    		
    		// do something with the member data
    	}
    	
    }

    Then in a template, you could put: <?php diego_show_groups(); ?>

    Only you know exactly what you’re trying to do.
    As I said: Where and when you place the data is up to you.


    diegomiguel05
    Participant

    @diegomiguel05

    Thank you for your help @shanebp.

    Data are collected, but I couldn´t be able to get a structured list of the groups members.

    Thanks again. Regards.

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