Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom members directory breaks pagination

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

  • DesignFirm
    Participant

    @designfirm

    After searching a little more, I found the ‘page_arg’ argument in bp-members-template.php. The url in the file directed me to here.

    Following the example there, I changed <?php if ( bp_has_members( bp_ajax_querystring( ‘members’ ) . ‘per_page=2’ ) ) : ?>

    to

    <?php if ( bp_has_members( ‘page_arg=bpage&per_page=2’ . bp_ajax_querystring( ‘members’ ) ) ) : ?>

    That did change the URL of the pagination to “http://localhost/twopointohla/bloggers-directory/?bpage=2&#8221; but clicking the second page still results in “Sorry, no members were found.”


    DesignFirm
    Participant

    @designfirm

    Perhaps more code would help?

    <?php if ( bp_has_members( 'page_arg=bpage&per_page=3' . bp_ajax_querystring( 'members' )  ) ) : ?>
    
    	<?php do_action( 'bp_before_directory_members_list' ); ?>
    
    	<ul id="members-list" class="item-list" role="main">
    
    	<?php while ( bp_members() ) : bp_the_member(); 
    	$user = new WP_User( bp_get_member_user_id() );
    	if ( ($user->roles[0] == 's2member_level3') || ($user->roles[0] == 's2member_level4') ) : ?>

    As I said, the user query works, but it seems to cause problems with the pagination.


    Boone Gorges
    Keymaster

    @boonebgorges

    It’s hard to tell exactly without knowing more about how you’ve customized your templates, but it’s possible that this is a problem only with AJAX. A quick fix may be to disable AJAX pagination for the members directory. Do so by adding the ‘no-ajax’ class to the .pagination div, ie

    <div id="pag-top" class="pagination no-ajax">

    If you’re still having problems, please post more details about how your theme is set up – whether it’s a child of bp-default, which default templates you are overriding in your theme, and perhaps the content of the custom templates themselves.


    DesignFirm
    Participant

    @designfirm

    Hi Boone,

    Thanks for the response. The “no-ajax” class did load users on subsequent pages, but I’m still experiencing other odd behavior:

    If I have the &per_page argument like this: `
    <?php if ( bp_has_members( bp_ajax_querystring( ‘members’ ) . ‘&page_arg=bapage&per_page=10’ ) ) : ?>` I receive no members on the first page, and two members on the second page if the filter is set to “newest registered” or “last active”. If it’s set to “alphabetical”, one member shows up on the first page, none on the second page, and one on the third page.

    If I remove the &per_page argument, I get both members on the first page for “newest registered” and “last active.” For “alphabetical”, I get one member on the first page, and one on the second.

    I’m using the social buddy theme. It’s set up like this:

    socialbuddy/buddypress/
    ajax.php
    functions-buddypress.php
    global.js
    style-buddypress.css

    socialbuddy/members/
    index.php
    members-loop.php
    single/(a bunch of files)

    I’ve added bloggers.php, which is a modified members’ index.php that I’m using as my page template, to the main “socialbuddy” folder. I changed the locate_template() function so that it uses my modified members-loop: members-loop-bloggers.php, which I’ve placed in the “members” folder.

    Thanks for any insight you can provide.

    Regards,
    Scott


    Boone Gorges
    Keymaster

    @boonebgorges

    The problem is, in essence, this: You are filtering for member type/role at the template level, *after* the query has already taken place. So: you run bp_has_members(). It returns 10 users that match the current params, which include the current page, the per_page number, and the dropdown filter (last active, alphabetical, etc). Then, inside of your template loop, you are only displaying a subset of those ten returned members – ie, those that match your s2member role.

    In order to make a custom directory *and* have your pagination work, you’ll need to modify the query *before* it happens. One relatively simple way to do this is to pass an include parameter to bp_has_members(), which would limit the query to users that meet your s2member criteria.

    Because we’re talking about custom user roles as assigned by s2member (and because user roles are stored in a way by WP that doesn’t allow this kind of query to be very efficient), this is going to be pretty tricky. This is totally untested, and probably not very fast at very large scale, but you could try something like the following:

    <?php 
    global $wpdb;
    $level3_user_ids = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%s2member_level3%'" );
    $level3_user_ids_param = implode( ',', $level3_user_ids );
    
    if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&page_arg=bapage&per_page=10&include=' . $level3_user_ids_param ) ) : ?>

    Then you will *not* need to do the level3 check inside the loop, because the 10 items returned will already be limited properly.

    Like I said, this is off the top of my head and may not work without further modification. You may have to do some more experimentation to get an accurate whitelist of user ids for each directory type. But, no matter how you do it, the above example should show you a good technique for limiting the bp_has_members() query to a subset of all users (which is the BuddyPress-related part of this puzzle – the other problem is related to s2member).


    DesignFirm
    Participant

    @designfirm

    Thanks a lot. I’ll give it a try!

    Scott


    DesignFirm
    Participant

    @designfirm

    Hello again,

    The query you wrote worked, but I can’t figure out how to get the search field and orderby filter to only re-query the two roles I’m initially querying by.

    Is there an easy way to do this?

    Sorry, I tried to make sense of how this stuff works, but anything beyond slight modifications is beyond me at this point.

    Thanks for any help you can provide.

    Scott

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom members directory breaks pagination’ is closed to new replies.
Skip to toolbar