Customising members-loop pagination
-
First of all I am using WordPress 4.1.1 and BuddyPress 2.2.2.1 and I am creating custom templates (via a custom plugin) that show Members based on roles. For example I want to have one page of only subscribers and another of only contributors. I have found a few different ways to doing this the simplest being to add a conditional statement like so
$user = new WP_User( bp_get_member_user_id() ); if ( $user->roles[0] =='subscriber'){ ?>
within the bp members loop.
The problem with this is that the pagination is skewed and is based on all the members instead of just those with the correct role. For example if I have 2000 members and only 5 of them are subscribers I will have pagination based on the 2000 where most pages are blank.
I’ve read suggestions to modify the
bp_members_pagination_count()
but it seems that changing the parameters ofbp_has_members()
would be more efficient. Therefore I would need to modifybp_ajax_querystring( 'members' )
in( bp_has_members( bp_ajax_querystring( 'members' ) ) ) :
I saw this thread by @zintax and modified it to suit my needs like so:
function modify_members_loop( $qs=false, $object=false ) { if ( $object != 'members' ) // hide for members only return $qs; // create an array with my subscribed users $subscribers = get_users( 'role=subscriber' ); $sub_list= array(); foreach ( $subscribers as $sub ){ $sub_list[]= $sub->ID; } $sub_list = implode(', ', $sub_list); if ( !empty( $args['include'] ) ) $args['include'] = $args['include'] . ',' . $sub_list; else $args['include'] = $sub_list; $qs = build_query($args); return $qs; } add_action( 'bp_ajax_querystring' , 'modify_members_loop', 25, 2 );
(I will later add conditionals so that this only occurs on the subscriber page)
I was wondering if this is indeed the best and most query efficient way to go about this or if there are other considerations I should be mindful of.
- The topic ‘Customising members-loop pagination’ is closed to new replies.