Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress: Output a second members loop for a customized list of UserIDs


  • sx1001
    Participant

    @sx1001

    I have a code / plugin which derivates a list of UserIDs by some logic which I want to display in a separate page in a sort of members loop.

    I tried similarly to this code, setting the args and than loading the template, it simply does not display the members:

    
        $members_args = array(
    			'include'         => array(list of user ids here ... 1, 13, 25, 126, ...),
    			'exclude'         => array(bp_loggedin_user_id()),
    			'per_page'        => $max_members,
    			'max'             => $max_members,
    			'populate_extras' => true,
    			'search_terms'    => false,
    		);
            
    	echo '<div id="buddypress" class="buddypress-wrap bp-dir-hori-nav bp-shortcode-wrap">';
    	echo '<div class="members">';
    	echo '<div class="subnav-filters filters no-ajax" id="subnav-filters">';
    	bp_get_template_part( 'common/filters/grid-filters' );
    	echo '</div>';
    	echo '<div class="screen-content members-directory-content">';
    
    	echo '<div id="members-dir-list" class="members dir-list">';
    
        buddypress()->current_member_type = "my separate loop";
        buddypress()->current_component   = 'members';
        buddypress()->is_directory        = true;
    
    	// Get a BuddyPress members-loop template part for display in a theme.
    	bp_get_template_part( 'members/members-loop' );
    
    	echo '</div>';
    	echo '</div>';
    	echo '</div>';

    I also tried instead to modify the query args like so instead of setting $members_args, but this does not work neither:

    
        $include = array(1, 13, 25, 126, ...); # list of user IDs to show
        add_filter ('bp_ajax_querystring', 'modify_directory', 20, 2);
        function modify_directory ($query_string, $object)
        {
            if ($object != 'members')  return $query_string;
    
            if (!empty ($query_string))  
                $query_string .= '&';
    
            $query_string .= 'include='. implode(',', $include).'&exclude='.bp_loggedin_user_id();
            return $query_string;
        } 

    Any idea?

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

  • shanebp
    Moderator

    @shanebp

    In your first section, you define $members_args but you never use it.
    For example: bp_has_members( $members_args ) ...

    In the second section, move the definition of $include into the function.
    Variables are not global unless defined as such.


    sx1001
    Participant

    @sx1001

    Okay, but how to use a variable outside a function and pass it to the callback function?

    I think version 1 is cleaner – BUT: unfortunately to use $members_args, unfortunately I have to change members loop – which I’d like to keep to the original one if possible.

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