#35484
 Laura
Moderator

Hello 🙂
This should work, add this to bp-custom.php in plugins folder then just change the profile field id (you can see it at Users > Profile Fields > I’m a > Edit )
and change the number 852 for your profile field id 🙂
I customized this code for you.

COPY CODE

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;

    //figure out if the logged-in user is male or female
   $sex = xprofile_get_field_data( 852, bp_loggedin_user_id() );

   if ( $sex == 'Muslim' ) 
      $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 852 AND value = 'Muslima'";
   else 
      $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 852 AND value = 'Muslim'";          


    $custom_ids = $wpdb->get_col( $query );


    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 $new_count;

    }
}

function custom_user_ids( ) {

    new BP_Custom_User_Ids ();

}

add_action( 'bp_before_directory_members', 'custom_user_ids' );

Delete the profile field “Looking for” so they can not search by gender. And also dont put any buddypress recent users widget anywhere but directory of members, also if you want to hide members loop at search form you can by going to Sweetdate > Homepage > Turn off members carousel
Also in home page delete members carousel shortcode 🙂

What does this do?
If a male goes to members directory he will only see females, same with females.

Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

Log in with your credentials

Forgot your details?