Find Answers and Get Support › Forums › Gwangi – PRO Multi-Purpose Membership, Social Network & BuddyPress Community Theme › Popular Features › Members Directory › Restrict by gender
- This topic has 1 reply, 2 voices, and was last updated 4 years, 4 months ago by
Themosaurus.
-
AuthorPosts
-
Malas RedaParticipant@malasreda
- 13 Topics
- 28 Posts
Hey,
You have already gave me this snippet wich works perfectly:
add_filter ( 'bp_ajax_querystring', 'gwangi_modify_members_loop', 20, 2 ); function gwangi_modify_members_loop( $qs = false, $object = false ) { global $wpdb; if ( $object != 'members' ) return $qs; $field_id = xprofile_get_field_id_from_name( 'What are you looking for ?' ); $filter_field_id = xprofile_get_field_id_from_name( 'What gender are you ?' ); // figure out if the logged-in user is male or female $gender = xprofile_get_field_data( $field_id, bp_loggedin_user_id() ); if ( ! empty( $gender ) ) { $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = {$filter_field_id} AND value = '{$gender}'"; } $custom_ids = $wpdb->get_col( $query ); $args = wp_parse_args ( $qs ); $args['include'] = implode ( ',', $custom_ids ); $qs = build_query ( $args ); return $qs; }
But when i have changed the field “what are you looking for ?” to a check box with multiple choice instead of radio, this snippet won’t work any more !
Is there any solution to make it work?This is the previous topic wich is closed now :https://support.themosaurus.com/forums/topic/restrict-directory-by-gender/
January 31, 2019 at 16:27 #5008@themosaurus- 1 Topics
- 1676 Posts
Hi @malasreda,
That snippet is indeed not designed to work with checkbox fields. However I think it should work with a small change:
add_filter ( 'bp_ajax_querystring', 'gwangi_modify_members_loop', 20, 2 ); function gwangi_modify_members_loop( $qs = false, $object = false ) { global $wpdb; if ( $object != 'members' ) return $qs; $field_id = xprofile_get_field_id_from_name( 'What are you looking for ?' ); $filter_field_id = xprofile_get_field_id_from_name( 'What gender are you ?' ); // figure out if the logged-in user is male or female $genders = xprofile_get_field_data( $field_id, bp_loggedin_user_id() ); $genders = esc_sql( $genders ); $genders = implode( "','", $genders ); if ( ! empty( $gender ) ) { $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = {$filter_field_id} AND value IN ('{$genders}')"; } $custom_ids = $wpdb->get_col( $query ); $args = wp_parse_args ( $qs ); $args['include'] = implode ( ',', $custom_ids ); $qs = build_query ( $args ); return $qs; }
Please try to replace the snippet I previously gave you by this one and keep me updated.
Best regards,
January 31, 2019 at 18:03 #5016 -
AuthorPosts
Hi there,
This topic has been inactive for a while now so we will be closing it to keep the forum tidy. Don't hesitate to create a new topic if you still need help and we'll be glad to help you!
Best regards,
The Themosaurus team.
The topic ‘Restrict by gender’ is closed to new replies.