Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to count the number of result in a members loop?


  • corporateslave
    Participant

    @corporateslave

    if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&per_page=12&exclude=1,2,3' ) ) :
    	do_action( 'bp_before_directory_members_list' );
    	while ( bp_members() ) : bp_the_member();
    		// print loop output here
    	endwhile;
    	do_action( 'bp_after_directory_members_list' );
    	bp_member_hidden_fields();
    else:
    	// found nothing
    endif;

    the code above is a basic example of custom members loop, with a defined posts_per_page and a number of IDs to exclude.

    Question:
    How do I get the total number of the result?

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

  • Venutius
    Moderator

    @venutius

    One thing I’d try would be to get it from the members template:

    global $members_template;
    
    $count = $members_template->total_member_count;

    This is what’s used to work out the pagination count for the members page to hopefully it takes into account the excluded members. Not tried out though.


    corporateslave
    Participant

    @corporateslave

    It works!
    Even with the exclusions… the number still came out correctly!!

    Thank You @Venutius

    — CASE CLOSED —

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