Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_has_members not working after update


  • b2marketing
    Participant

    @b2marketing

    Hi I used to filter the members-loop-php with the code below. I only want to show members who has agreed to making their profile public.

    
    <?php if ( bp_has_members( 'search_terms=Make_My_Profile_Public' ) ) : ?>
    
    

    However this is not working after updating to 2.1.1

    I tried looking through change log but could not see any changes that would affect my code.

    Thank you for any help you can provide.
    Philip

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

  • danbp
    Moderator

    @danbp

    @b2marketing,

    do you used a child-theme to make this change ?


    b2marketing
    Participant

    @b2marketing

    Hi

    Yes I have it like this: childtheme/buddypress/members/members-loop.php and it is picking up the template because no members shows up and if I remove the “members-loop.php” file then the members shows up but all of them. So when using my “if” statement then it removes all members even the members who has chosen the drop down “Make_My_Profile_Public”


    danbp
    Moderator

    @danbp

    i guess you do it wrong. 😉

    How have you implemented “Make_My_Profile_Public” ?
    Is this a custom profile field of yours ?


    b2marketing
    Participant

    @b2marketing

    Hi

    Sorry had to go to bed.

    Yes it is a custom profile field I created and it is working when using Buddypress 2.0.2 but updating to latest 2.1.1 then all members disappear from the loop and I just get the “else” statement saying: No members found.

    I created the custom field by going to users -> profile fields.
    I then use the if statement above like this. Please see gist.
    https://gist.github.com/philipb2/bd689aa4b843235ec414

    Thanks


    danbp
    Moderator

    @danbp

    Here’s a snippet to filter members list based on profile field.

    Remove your custom members-loop file first and revert to default one.

    The example use field ID 62 with value = public
    The field is called Privacy in xProfile and use a selectbox field type who shows 2 options: private and public.

    You’ll probably also have to remove, or to conditionnally show, the top navbar, search box, etc in the template (childtheme/buddypress/members/index.php)

    Add this snippet to bp-cutom.php.

    class BP_Custom_User_Ids {
    	private $custom_ids = array();
    	public function __construct() {
    		$this->custom_ids = $this->get_custom_ids();
    		add_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 );
    		add_filter( 'bp_get_total_member_count', array( $this, 'custom_members_count' ), 1, 1 );
    	}
    	
    	private function get_custom_ids() {
    		global $wpdb;
    		// collection based on an xprofile field
    		$custom_ids = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 62 AND value = 'Public'");
    		return $custom_ids;
    	}	
    	
    	function custom_members_query( $query_array ) {
    		$query_array->query_vars['include'] = $this->custom_ids;
    	}	
    	
    	function custom_members_count ( $count ) {
    		$new_count = count( $this->custom_ids );
    		return $count - $new_count;		
    	}
    }
    
    function custom_user_ids( ) {
    	new BP_Custom_User_Ids ();
    }
    add_action( 'bp_before_directory_members', 'custom_user_ids' );

    Props @shanebp (tip on github)


    b2marketing
    Participant

    @b2marketing

    Thanks danbp

    Really sorry to bother you again.

    I implemented this but it is not removing anyone from the loop. I looked at the gist you linked too and (with my limited php experience) combined with the text in the top

    Filter Members List Based On Profile Field – Female members are served a directory of males and male members are served a directory of females.

    then I am wondering if I have not explained myself properly.

    I want to hide/remove members from the loop who has chosen “private” in their profile. I don’t want any members to be able to see members who has chosen “private”.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘bp_has_members not working after update’ is closed to new replies.
Skip to toolbar