Support only during business hours : Monday to friday, from 8:30 am – 5:30 pm CEST

Due to the decrease in our staff due to vacations, our response time may be longer.

Be sure we're doing our best to manage your topic as soon as possible.

Restrict by gender

This topic is resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Malas Reda
    Participant
    • 13 Topics
    • 28 Posts
    @malasreda

    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/

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1675 Posts
    @themosaurus

    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,

Roboraptor 🦖
Themosaurus Topic Closer

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.

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

The topic ‘Restrict by gender’ is closed to new replies.

Troubleshooting Demo Imports

You're trying to setup your theme but you're experiencing errors when importing the demo content? Or you've just followed the setup guide but your website doesn't look exactly like our demo? These are common issues for which you can find easy and quick fixes.

Happy With our Support So Far?

Feel free to review our theme on Themeforest! It helps us making our products more known to new potential customers, which allow us more time to improve the quality and develop new features. #SharingIsCaring ❤️

Discover MatchPress

Skip • Like • Super-Like

Add powerful matching features like Member likes, skips, super likes, conditional private messaging and much more.

Setup Your Cera or Gwangi powered Community Website and Turn it into an iOS and Android App

15% discount for Cera users

To unleash the full power of your Cera or Gwangi theme, we have partnered with the Zipline team. Your community website can now be fully setup and turned into your very own custom app for iOS and Android.

Whether you've newly acquired the theme or already got your site up and running, Zipline got you covered. And we got you an incredible discount.

Holiday, Weather & Festive effects
to pimp your WordPress Site