Skip to:
Content
Pages
Categories
Search
Top
Bottom

Members Directory Pagination Help!


  • RiGoRmOrTiS_UK
    Participant

    @rigormortis_uk

    Hi All,

    I’m currently trying to filter users of a certain role from my members directory in buddypress; I’ve managed to write a function (member_loop_role) which returns their role and then I filter against that in members-loop.php with the following code:

    <?php while ( bp_members() ) : bp_the_member(); ?>
    
    	<?php if ( member_loop_role() == 'bbp_blocked') continue; ?>
    

    This removes any user with the role of bbp_blocked (bbpress blocked role). However pagination on the members directory still counts all the users which I’m hiding, meaning you get some pages showing members 1-20; but only listing a portion of those users; naturally this caused major inconsistency from page to page.

    I know pagination is handled by the functions bp_members_pagination_count() and bp_get_members_pagination_count() in bp-members-template.php however no matter what I try I simply can’t understand how that code works or how to make it reduce the member count by the number of user’s I’ve hidden from the members directory.

    Can anyone help with this? really desperate to get this sorted and I’ve been trying for weeks without success.. I’m sure one of you guys will look at those above function and know the fix in an instant; but I simply don’t have the PHP experience. Thanks in advance for any help you can provide!

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

  • meg@info
    Participant

    @megainfo

    I think you can’t show the correct number, because you do the test about role of bbp_blocked in the loop, so the number of members is uknow before the loop, buddypress save the number of members before the loop in variable $total_member_count

    check bp_core_get_total_member_count() function.

    I think if you check how buddypress profil search work, you will find a solution for your problem.
    https://wordpress.org/plugins/bp-profile-search/

    Regards,


    boydspace
    Participant

    @boydspace

    @rigormortis_uk, did you get this to work and how did you do it? If it is not too much to ask, can I have a copy of all the files you worked on? I want to do the exact same process, but with a custom role I made.

    All help would be greatly appreciated.

    Thanks!


    RiGoRmOrTiS_UK
    Participant

    @rigormortis_uk

    Hi @boydspace Nope I tried looking at files for the plugin @megainfo recommended but unfortunately I didn’t understand any of the code. I’m totally winging it when it comes to PHP.

    I’m now trying to tackle it from another angle; the members directory doesn’t list any members without activity (e.g. have never logged in). So my new angle of attack is to remove the meta data holding when they last logged in if their current WordPress role is “bbp_blocked”.

    I’ve created a new function called “clr_activity()” which I call in members-loop.php as such:

    <?php while ( bp_members() ) : bp_the_member(); ?>
    
    	<?php clr_activity() ?>

    The contents of the function which is held in my theme’s functions.php are:

    function clr_activity() {
    
    	/********* GET USERS ROLE ********/
    	global $members_template;
    	$user_id = $members_template->member->id;
    	$user = new WP_User($user_id);
    	$user_role = array_keys($user->wp_capabilities,"1");
    	
    	/********* IF USER BLOCKED CLEAR LAST ACTIVITY ********/
    	if ( $user_role[0] == 'bbp_blocked') 
    	{
        		bp_update_user_meta( $user_id, 'last_activity', ' ' );
    	}
    	else
    	{
    		return 0;
    	}
    }

    Before I even try to implement this I hope someone with greater PHP knowledge can check I’m using bp_update_user_meta correctly; for one thing I’m not sure the empty quotes will give me the desired value in the user’s last_activity meta field. I want it to be clear as if the user has never logged in.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Members Directory Pagination Help!’ is closed to new replies.
Skip to toolbar