Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Carsten,

    Try this code instead:

    add_filter ('bp_ajax_querystring', 'modify_members_loop', 20, 2);
    function modify_members_loop ($qs=false, $object=false)
    {
    	global $wpdb;
    	if ($object != 'members')  return $qs;
    
    	// figure out if the logged-in user is male or female
    	$gender = xprofile_get_field_data (5, bp_loggedin_user_id ());
    
    	if ($gender == 'Male')
    		$query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 5 AND value = 'Female'";
    	else
    		$query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 5 AND value = 'Male'";
    
    	$custom_ids = $wpdb->get_col ($query);
    
    	$args = wp_parse_args ($qs);
    	$args['include'] = implode (',', $custom_ids);
    	$qs = build_query ($args);
    
    	return $qs;
    }

    Replace 5 with the field ID of your ‘Gender’ field.

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hello, and thanks for the code. I am not sure, how to find the field ID, I can only find class=”field_1877 for the gender select box, is this the one?

    Regards

    Plugin Author Andrea Tarantini

    (@dontdream)

    Yes, replace 5 with 1877 and please let me know how it goes!

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, success, it did the job indeed, thanks!

    Just a remark, I tested this code again:
    https://gist.github.com/anonymous/7913816#file-bp-custom-php, without any conflicts with BP Search.
    One interesting thing about this code is, that it also affects the BuddyPress Members and Recently Active Members widgets, by listing the relevant gender, which is a most wanted feature.

    Unfortunately it returns the female directory to both male and female members, I can’t figure out why.

    Regards
    Carsten

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Carsten,

    Great, I’m glad it worked!

    About the github code, if you don’t succeed in debugging it you could post a comment there. I’m afraid I don’t have enough available time to look into it myself – sorry!

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, thanks, no of cource not, this was only for your information, I did not expect you to solve this issue, as this has nothing to do with your own work.

    Regards
    Carsten

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, thanks, no of cource not, this was only for your information, I did not expect you to solve this issue, as this has nothing to do with your own work.

    Regards
    Carsten

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, sorry about the doublet answer.

    I have one question about where to place the code you gave me.

    I placed it in bp.custom.php, but should it be in members-loop.php instead?

    Regards and thanks!

    Carsten

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Carsten,

    All the BuddyPress custom code should go into bp-custom.php, but it could work in other files too. I prefer to put it all into bp-custom.php so I know where to look for it ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Conflict with gender based directory?’ is closed to new replies.