This topic has 1 reply, 1 voice, and was last updated 8 years by gugga7.

  • Author
  • #95489
     gugga7
    Participant

    I got the Opposite gender restriction to work but the search filters in the /members page stopped working after I added the code to functions.php.

    There must be something in the code that was given before that messes up the regular search filters. Can you please help with this? This is the one thing left for me before I can go live. I fixed all the other issues. Thanks.

    `/* GENDER RESTRICT */

    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( 3, bp_loggedin_user_id() );

       if ( $sex == ‘Man’ )

          $query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = ‘Woman'”;

       else

          $query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = ‘Man'”;

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

        return $custom_ids;

    }

        function custom_members_query( $query_array ) {

            $query_array->query_vars[‘user_ids’] = $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’ );`

    #95513
     gugga7
    Participant
    This reply has been set as private.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Opposite gender filtering…’ is closed to new replies.

Log in with your credentials

Forgot your details?