Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Alphabetically Displaying Only Buddypress Users in Multisite


  • ericreynolds007
    Participant

    @ericreynolds007

    I am using Buddypress 2.1.1 for one of my Multisites in WP 4.0.

    Currently, when a BP site member alphabetically sorts the member directory, aside from the BP site members, the loop also displays users from all of my Multisite sites. Is there a way that the member directory can filter and only display BP users alphabetically?

    🙂 Eric

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

  • shanebp
    Moderator

    @shanebp

    Is it only alphabetical that does that?
    ‘Last Active’ shouldn’t.
    What about ‘Newest Registered’ ?

    Alphabetical sorts against the display_name field in the wp_users table, so you might have to write a filter.
    How many BP users do you have?


    ericreynolds007
    Participant

    @ericreynolds007

    Thanks for the prompt response, Shane.

    Yes, only the alphabetical sort displays all MS users. The issue is that the BP site is a private Board of Directors site, while the other sites are maintained by users that are employees and have no business showing up as members of the private BP site.

    There are only 12 board members that are BP users vs. 100+ employee users for the other sites.

    Any idea of how to write the filter?

    🙂 Eric


    shanebp
    Moderator

    @shanebp

    This will get you started re filter:

    function ericreynolds007_filter_ajax_querystring( $querystring = '', $object = '' ) {
    
    	if( $object != 'members' )
    		return $querystring;
    
    	$defaults = array(
    		'type'            => 'active',
    		'action'          => 'active',
    		'scope'           => 'all',
    		'page'            => 1,
    		'user_id'         => 0,
    		'search_terms'    => '',
    		'exclude'         => false,
    	);
    
    	$dtj_querystring = wp_parse_args( $querystring, $defaults );
    
    	if( $dtj_querystring['type'] == 'alphabetical' ) {
    	
    		$users = get_users('role=editor');
    			
    		$users_str = '';
    		foreach ( $users as $user ) {
    	           $users_str .=  $user->ID . ',';
    	        }
    		$users_str = rtrim($users_str, ",");
    		
    		$dtj_querystring['include'] = $users_str; 
    		
    		return $dtj_querystring;
    		
    	}
    	else
    		return $querystring;
    			
    }
    add_filter( 'bp_ajax_querystring', 'ericreynolds007_filter_ajax_querystring', 20, 2 );

    The key parts are the ‘include’ which restricts the query to those users.
    This example gathers all users with role=editor.
    You’ll have to figure out how to collect the ids of the board members.
    You might try using the ‘type’ field in the bp_activity table.
    SELECT user_id FROM .... WHERE type = 'last_activity'


    ericreynolds007
    Participant

    @ericreynolds007

    Thanks so much Shane. I really appreciate it. 🙂


    DrakeDoc
    Participant

    @drakedoc

    Thank you Shane. I was facing same difficulty. Your help is really appreciated.


    ericreynolds007
    Participant

    @ericreynolds007

    Hi Shane, I’ve gone a different route, hoping to avoid adding user IDs everytime a new Board Member joins the BP site.

    From a support request, I discovered that I could exclude or include roles to display in the members loop by adding the following code to the members-loop.php. For the private BP site, using the Members plugin, I created a new role, “bod_member” and reassigned the few members this role. I then added the following code to include only the bod_member…

    <?php while ( bp_members() ) : bp_the_member();
    $user = new WP_User( bp_get_member_user_id() );
    if ( $user->roles[0] == 'bod_member' ) :
    ?>

    Unfortunately, upon saving the file, the site returned a parse error, referencing the code below:

    <?php endwhile; ?>

    The error begins with “Parse error: syntax error, unexpected ‘endwhile'”

    Am I doing something wrong?

    🙂 Eric


    shanebp
    Moderator

    @shanebp

    Try adding this just above the endwhile

    <?php endif; ?>

    btw – this isn’t the proper forum for basic php coding questions.


    ericreynolds007
    Participant

    @ericreynolds007

    Fantastic! That did it. I apologize for posting in the wrong forum.

    🙂 Eric

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Alphabetically Displaying Only Buddypress Users in Multisite’ is closed to new replies.
Skip to toolbar