This topic has 20 replies, 8 voices, and was last updated 9 years by Artem.

  • Author
  • #38288
     Laura
    Moderator

    Hello, many of you wanted to restrict some member fields from finding their same sex/field, so this code will do it, you only need to make a simple changes and it will do the work.

    First, find out what is the field id you want to use, like Gender/Sex so if i choose Female, i can only find Male.

    1. Find field ID (Attachment 1)

    2. Change the number 38 in the code for your field ID

    3. Change the Names in the code for your field names (Male/Female)

    4. IMPORTANT! Dont change nothing more.

    5. IMPORTANT! Profile fields id NEVER starts with a 0

    6. Code in functions.php of child theme

    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 == 'Male' ) 
          $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 38 AND value = 'Female'";
       else 
          $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 38 AND value = 'Male'";          
    
    
        $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' );
    
    #40674
     cruchot
    Participant

    Hello,

    Which file edit to add this code?

    Thanks

    #40710
     Laura
    Moderator

    Hello, add this to your functions.php in child theme

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

    Hello, I need help for my website

    [Opposite SEX]

    1 – look at the screen
    2 – I also love that men can send private messages only to women and women to men only
    3 – And I would like to “Arrowchat” , view only members of the opposite sex
    4 – And if possible with the plugin “paid memberships pro” , I want women directly free Membership

    Sorry for my english

    Thank you very much for your help

    #40834
     Laura
    Moderator

    Hello, will work on a solution for you, but for Arrowchat you would need to contact their support.
    2.You should contact a developer to do this for you as it requires extra custom work.
    3.Check out this post https://archived.seventhqueen.com/forums/topic/membership-auto-in-registration#post-5411
    To disable changing gender after registration use this code:

    COPY CODE
    
    function disable_name_change( $data ) {
    
    if ( 852 == $data->field_id )
    
    $data->field_id = false;
    
    
    
    return $data;
    
    }
    
    add_action( 'xprofile_data_before_save', 'disable_name_change' );
    

    IMPORTANT Change 852 for the “I am a” Field ID (located in the url when you edit the field)
    If they try to change gender and save, it will show an error message.

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

    It working good for once load members page.
    http://rateurdates.com/members
    But when i click on page number in pagination then it’s can’t work properly.
    In next page it will shows all member (Means male and female both).
    So can you help me how to fixed this problem.
    Page No1:
    PageNumber:01
    Page No2:
    PageNumber:01

    #41738
     tdate
    Participant

    Rateurdates.com
    user:staff982
    pwd:OverLord777%$22

    #42272
     Abe
    Keymaster

    Hi, right now the code could have some problems and we will try to fix them and once we do that we will include it in the theme.

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

    Can you please tell me when you will fixed it?
    I want to fixed this issue ASAP in my current theme code.
    Because it’s urgent for me.

    #42439
     Abe
    Keymaster

    This is just a custom code given here from a user contribution and not in the theme as a feature. Can’t really say when we will update this code. Will keep you posted

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

    I have this same issue when viewing other pages. The Gender always comes back. Can it be revisited and fixed? Thanks.

    #78333
     Abe
    Keymaster

    Hi, are you using the latest theme version since it should be fixed?

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

    This is useless unfortunately. If you change any search criteria, it will go back to showing both genders…

    #95457
     Abe
    Keymaster

    Can you check it on the demo since I can’t reproduce it?

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

    May be I misunderstood but this restriction and code is not installed on your demo so I can’t test it there.

    #97507
     Abe
    Keymaster

    Sorry for that, you are right and that solution is just a workaround and not a fully tested one and can be a starting point for your development.

    CHeers

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

    Isn’t there a simpler way of doing this, instead of re-writing search code? The horizontal search bar works, so when a user goes to the Members page, couldn’t those search fields be pre-populated with the values the user gives when they sign up (age range, I am a…, Looking for a… etc.), and then an immediate search done from that using the built in Search feature? After that, if the user wants to adjust any of the search criteria, they can do so in the search bar. I don’t want to allow a user to change their gender or the gender they are looking for once they have signed up, so I’m sure the ‘I am a…’ & ‘Looking for a…’ fields could be hidden in the search bar, even though they are used in the search.

    #112229
     Abe
    Keymaster

    we are at the point of rewriting Sweetdate theme and making it more actual with Visual composer and better shortcodes and options.

    That should be achieved this year.

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

    ok that’s great news, but in the meantime do you know of a way in which the search criteria can be pre populated with a member’s preferences, and then a search automatically made when the ‘Members’ page loads?

    #112431
     Abe
    Keymaster

    I think it will imply some custom template changes so there isn’t a quick solution for that unfortunately.

    All the best.

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

    Laura can you add this code to my website? When i try doing this my website crashes. Thanks.

Viewing 21 posts - 1 through 21 (of 21 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?