Sorting my custom members-loop-2 loses the filtering

BP Profile Search › Sorting my custom members-loop-2 loses the filtering

  • Author
    Post
  • #9529 Reply
    Panos
    Guest

    Hi Andrea,
    I am hoping you can help me with this issue. I’ve spent days trying to figure it out and even on BuddyPress they’re not helpful with this.
    I followed your steps and created a custom directory (members-loop-2.php, index-2.php etc.). I have a function that generates the user IDs (if ( bp_has_members( bp_ajax_querystring( 'members' ) .'&include=' .get_user_matches().'&exclude=1' ) ) :). It all works just fine, until I sort the results. Then it’s like it’s reverting back to the default directory results and brings back everyone. This doesn’t happen in the directory that has your bp-profile-search so I know there’s a way to accomplish this.
    Any ideas and guidance would be very greatly appreciated!!!
    Thank you!

    #9531 Reply
    andrea
    Plugin Author

    Hi Panos,

    Instead of modifying members-loop-2.php, try using the bp_ajax_querystring filter hook, see this post.

    If you have bp_ajax_querystring filters for different directories, you can apply them based on the current page, using if (is_page (page ID)) inside the filtering function.

    Please let me know how it works!

    #9532 Reply
    Panos
    Guest

    I tried the below but now nothing works. Not the sorting and not even your profile search directory (it just defaults to all members regardless of the search criteria). When you first visit the default members-loop and the custom members-loop-2 the results are fine, but when you try to sort (i) it doesn’t sort and (ii) my custom members-loop acts like before, meaning it brings back all the users. Maybe I did it wrong?
    This is in both the default and the custom directory:
    ‘<?php if ( bp_has_members( bp_ajax_querystring( ‘members’ ) .get_desired_users() ) ) : ?>’

    And this is basically the function:

    function get_desired_users() {
    if ( is_page(456) ) { //this is my custom directory page
       //figure out the user's matches for the My Match xProfile fields 
       $include = implode(",", $my_matches);
       return '&include=' . $include . '&exclude=1,' . $my_user_id;
    } else { //this is the default and I guess the Profile Search directories
       //get the users that match the user's gender and gender preference 
       $include = implode(",", $my_matches);
       return '&include=' . $include . '&exclude=1,' . $my_user_id;
      }
    }
    add_filter ('bp_ajax_querystring', 'get_desired_users', 20, 2);

    Thanks for your continuous help!

    #9533 Reply
    andrea
    Plugin Author

    Hello Panos,

    Two suggestions:

    1. Do not modify your members-loop.php and members-loop-2.php files, restore them to their original BuddyPress code;

    2. Double check your function get_desired_users(), make sure that it defines its two standard args, that the $my_matches array is correctly populated, and the $query_string is correctly built and without the initial ampersand. Start from this code you reported was working for you.

    #9534 Reply
    Panos
    Guest

    Hi Andrea,
    First, maybe I should refer to my “default directory” (which is the home page) as custom_1 because that’s also customized, and my “custom directory” as custom_2.

    I restored the directories in their original state and checked my code, $my_matches and my queries but I don’t think that’s the problem otherwise it wouldn’t work from the beginning.
    I did an echo check to see what happens when I sort the directories and it seems that when you sort it, it doesn’t pick up the page that’s loaded and it just defaults to the custom_1 directory results. For example, when I’m on my custom_2 directory I have echo 'echo = ' . $added_args;, which is the db query string, which works fine. Then, if it’s not the custom_2 directory I have echo 'echo = Default';. Like this:

    function get_desired_users() {
    if ( is_page(456) ) { //this is my custom_2 directory page
       //figure out the user's matches for the My Match xProfile fields 
    		$my_matches = $wpdb->get_col( $added_args );
    		echo 'echo = ' . $added_args;
    		$include = implode(",", $my_matches);
    		return 'include=' . $include . '&exclude=1,' . $my_user_id;
    
    } else { //this is the custom_1 and I guess the Profile Search directories
       //get the users that match the user's gender and gender preference 
    		 $my_matches = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender')");
    		echo 'echo = Default'; 
    		$include = implode(",", $my_matches);
    		return 'include=' . $include . '&exclude=1,' . $my_user_id;
    
      }
    }
    add_filter ('bp_ajax_querystring', 'get_desired_users', 20, 2);

    So when I first load my custom_2 directory this works fine but when I sort it by Alphabetical order i get echo = Default which tells me that during the sorting it didn’t detect that I’m on my custom_2 directory and it processes the code in the else part of function get_desired_users().

    Also, the way it’s coded right now, your Profile Search directory doesn’t sort. When I try to sort it doesn’t really do anything.

    Something’s wrong in all this. I’m trying to figure out how you did it in your plugin (although I haven’t been able yet) because it obviously works without a problem. The way you did it it doesn’t revert back to the custom_1 directory.

    I don’t know, I’m lost. I can’t figure this out. I’ve spent so many hours on this my brain is fried. Any other suggestions? I can give you access to the site just so you can see what I mean, if that’s not too much to ask. You’ve been very helpful regardless so thank you!

    #9535 Reply
    andrea
    Plugin Author

    Hello Panos,

    I’m afraid I misled you with my suggestion to use is_page(). Sorry!

    That function doesn’t work during AJAX calls. Try using my function bps_current_page() instead, that returns the URL of the current page even during an AJAX call.

    #9551 Reply
    Panos
    Guest

    Hi Andrea,
    I tried what you said and it worked but I still had problems with sorting so I stripped it down and there’s something wrong with this whole thing. If I remove custom filtering and put the directory back to its default state, everything works fine. When I add a simple custom filtering, i.e. add_filter ('bp_ajax_querystring', 'home_dir', 20, 2);, it stops sorting. The thing is that it worked before so I don’t know what happened now. Your plugin doesn’t sort either but it did before so I need to figure this out. Maybe it’s the 3.0 update…who knows.

    Thanks again for all your help though!
    -Panos

    #9555 Reply
    andrea
    Plugin Author

    Hello Panos,

    Did you add the two args to your function get_desired_users()?

    It should be
    get_desired_users($querystring, $object)
    and should
    return $querystring;

    #9557 Reply
    Panos
    Guest

    I did. I’m pasting it below. The initial results are accurate. The user IDs that are passed are correct but when I sort by i.e. Alphabetical Order, it doesn’t sort. It just stays the same. This happens to all directories (my default custom directory, my Matches directory, and the Profile Search Directory).
    Thanks for helping out.

    function get_desired_users ($querystring, $object) {
    	
    if (  bps_current_page() === '/matches/' ) { //matches page
    
    		global $wpdb;
    		global $bp;
            if ($object != 'members')  return $querystring;
    		$my_user_id = bp_loggedin_user_id();
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		$i_am_looking_for = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND user_id = $my_user_id");
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		
    		$added_args = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender')";
    		
    		$my_preferred_state = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 374 AND user_id = $my_user_id");
    		if ( $my_preferred_state && $my_preferred_state != 'Any' ) $added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 201 AND value = '$my_preferred_state')";
    		
    		$my_preferred_city = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 455 AND user_id = $my_user_id");
    		if ($my_preferred_city && $my_preferred_city != 'Any' ) $added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 254 AND value = '$my_preferred_city')";
    
    		$my_preferred_min_age = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 427 AND user_id = $my_user_id");
    		$my_preferred_max_age = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 428 AND user_id = $my_user_id");
    		if ( $my_preferred_min_age && $my_preferred_min_age != 'Any'  ) {
    			$d=strtotime("-" . $my_preferred_min_age . " Years");
    			$my_preferred_max_age_converted = date("Y-m-d 00:00:00", $d);
    		}
    		if ( $my_preferred_max_age && $my_preferred_max_age != 'Any' ) {
    			$d=strtotime("-" . $my_preferred_max_age - 1 . " Years");
    			$my_preferred_min_age_converted = date("Y-m-d 00:00:00", $d);
    		}
    
    		if ( $my_preferred_min_age_converted && $my_preferred_max_age_converted )   {
    			
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value BETWEEN '$my_preferred_min_age_converted' AND '$my_preferred_max_age_converted')";
    		} elseif ( $my_preferred_min_age_converted && !$my_preferred_max_age_converted )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value >= '$my_preferred_min_age_converted')";
    		} elseif ( !$my_preferred_min_age_converted && $my_preferred_max_age_converted )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value <= '$my_preferred_max_age_converted')";
    		}
    				
    		$my_preferred_min_height = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 429 AND user_id = $my_user_id");
    		$my_preferred_max_height = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 430 AND user_id = $my_user_id");
    		if ( $my_preferred_min_height && $my_preferred_min_height != 'Any' && $my_preferred_max_height && $my_preferred_max_height != 'Any' )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 24 AND value BETWEEN '$my_preferred_min_height' AND '$my_preferred_max_height')";
    		} elseif ( ($my_preferred_min_height && $my_preferred_min_height != 'Any') && (!$my_preferred_max_height || $my_preferred_max_height === 'Any' ) )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 24 AND value >= '$my_preferred_min_height')";
    		} elseif ( (!$my_preferred_min_height || $my_preferred_min_height === 'Any') && ($my_preferred_max_height && $my_preferred_max_height != 'Any' ) )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 24 AND value <= '$my_preferred_max_height')";
    		}
    		
    $my_preferred_body_type = xprofile_get_field_data( 431, $my_user_id );
     if ($my_preferred_body_type) {
    	 if ( is_array( $my_preferred_body_type ) ) {
    		$my_preferred_body_type = array_slice( $my_preferred_body_type, 0, 8 );
    		$my_preferred_body_type = join( "','",$my_preferred_body_type );
    	 }
    	 	$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 16 AND value IN ('$my_preferred_body_type'))";
     }
     
    
     $my_preferred_has_kids = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 448 AND user_id = $my_user_id");
    		if ($my_preferred_has_kids && $my_preferred_has_kids != 'Any' ) $added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 10 AND value = '$my_preferred_has_kids')";
    		
    $my_preferred_wants_kids = xprofile_get_field_data( 451, $my_user_id );
     if ($my_preferred_wants_kids) {
    		$my_preferred_wants_kids = array_slice( $my_preferred_wants_kids, 0, 3 );
    		$my_preferred_wants_kids = join( "%') OR (field_id = 13 AND value LIKE '%",$my_preferred_wants_kids );
    		$my_preferred_wants_kids = "(field_id = 13 AND value LIKE '%" . $my_preferred_wants_kids . "%')";
    		$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE " . $my_preferred_wants_kids . ")";
     }
    
    $my_preferred_marital_status = xprofile_get_field_data( 456, $my_user_id );
    		if ( $my_preferred_marital_status ) {
    			$my_preferred_marital_status = array_slice( $my_preferred_marital_status, 0, 6 );
    			$my_preferred_marital_status = join( "') OR (field_id = 3 AND value = '",$my_preferred_marital_status );
    			$my_preferred_marital_status = "(field_id = 3 AND value = '" . $my_preferred_marital_status . "')";
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE " . $my_preferred_marital_status . ")";
    		}
    		
    $my_preferred_smokes = xprofile_get_field_data( 469, $my_user_id );
    		if ( $my_preferred_smokes ) {
    			$my_preferred_smokes = array_slice( $my_preferred_smokes, 0, 5 );
    			$my_preferred_smokes = join( "') OR (field_id = 160 AND value = '",$my_preferred_smokes );
    			$my_preferred_smokes = "(field_id = 160 AND value = '" . $my_preferred_smokes . "')";
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE " . $my_preferred_smokes . ")";
    		}
    
    		
    		//Get all matches
    		$my_matches = $wpdb->get_col( $added_args );
    		$include = implode(",", $my_matches);
    		$querystring = 'include=' . $include . '&exclude=1,' . $my_user_id;
    		return $querystring;
    	
    
    } else {
    		global $wpdb;
            if ($object != 'members')  return $querystring;
    		$my_user_id = bp_loggedin_user_id();
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		$i_am_looking_for = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND user_id = $my_user_id");
    	
    		//Get all users that are what the logged_in member is looking for
    		 $my_matches = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender')");
    		$include = implode(",", $my_matches);
    		$querystring = 'include=' . $include . '&exclude=1,' . $my_user_id;
    		return $querystring;
    
    	
    	} 
    }
    add_filter ('bp_ajax_querystring', 'get_desired_users', 20, 2);
    #9558 Reply
    andrea
    Plugin Author

    Hi Panos,

    The correct way to return the query string is as follows:

         if (!empty ($querystring ))  $querystring .= '&';
         $querystring .= 'include='. $include. '&exclude=1,'. $my_user_id;
         return $querystring;

    as mentioned in my original post of May 5.

    #9559 Reply
    Panos
    Guest

    That was it! Everything works!!!
    Thank you soooo much for stinking with this and helping me out Andrea! Can’t thank you enough.
    Cheers
    -Panos
    My working code:

    function get_desired_users ($querystring, $object) {
    	
    if (  bps_current_page() === '/matches/' ) { //matches page
    		global $wpdb;
    		if ($object != 'members')  return $querystring;
    		$my_user_id = bp_loggedin_user_id();
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		$i_am_looking_for = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND user_id = $my_user_id");
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		
    		$added_args = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender')";
    		
    		$my_preferred_state = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 374 AND user_id = $my_user_id");
    		if ( $my_preferred_state && $my_preferred_state != 'Any' ) $added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 201 AND value = '$my_preferred_state')";
    		
    		$my_preferred_city = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 455 AND user_id = $my_user_id");
    		if ($my_preferred_city && $my_preferred_city != 'Any' ) $added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 254 AND value = '$my_preferred_city')";
    
    		$my_preferred_min_age = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 427 AND user_id = $my_user_id");
    		$my_preferred_max_age = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 428 AND user_id = $my_user_id");
    		if ( $my_preferred_min_age && $my_preferred_min_age != 'Any'  ) {
    			$d=strtotime("-" . $my_preferred_min_age . " Years");
    			$my_preferred_max_age_converted = date("Y-m-d 00:00:00", $d);
    		}
    		if ( $my_preferred_max_age && $my_preferred_max_age != 'Any' ) {
    			$d=strtotime("-" . $my_preferred_max_age - 1 . " Years");
    			$my_preferred_min_age_converted = date("Y-m-d 00:00:00", $d);
    		}
    
    		if ( $my_preferred_min_age_converted && $my_preferred_max_age_converted )   {
    			
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value BETWEEN '$my_preferred_min_age_converted' AND '$my_preferred_max_age_converted')";
    		} elseif ( $my_preferred_min_age_converted && !$my_preferred_max_age_converted )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value >= '$my_preferred_min_age_converted')";
    		} elseif ( !$my_preferred_min_age_converted && $my_preferred_max_age_converted )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value <= '$my_preferred_max_age_converted')";
    		}
    				
    		$my_preferred_min_height = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 429 AND user_id = $my_user_id");
    		$my_preferred_max_height = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 430 AND user_id = $my_user_id");
    		if ( $my_preferred_min_height && $my_preferred_min_height != 'Any' && $my_preferred_max_height && $my_preferred_max_height != 'Any' )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 24 AND value BETWEEN '$my_preferred_min_height' AND '$my_preferred_max_height')";
    		} elseif ( ($my_preferred_min_height && $my_preferred_min_height != 'Any') && (!$my_preferred_max_height || $my_preferred_max_height === 'Any' ) )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 24 AND value >= '$my_preferred_min_height')";
    		} elseif ( (!$my_preferred_min_height || $my_preferred_min_height === 'Any') && ($my_preferred_max_height && $my_preferred_max_height != 'Any' ) )   {
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 24 AND value <= '$my_preferred_max_height')";
    		}
    		
    $my_preferred_body_type = xprofile_get_field_data( 431, $my_user_id );
     if ($my_preferred_body_type) {
    	 if ( is_array( $my_preferred_body_type ) ) {
    		$my_preferred_body_type = array_slice( $my_preferred_body_type, 0, 8 );
    		$my_preferred_body_type = join( "','",$my_preferred_body_type );
    	 }
    	 	$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 16 AND value IN ('$my_preferred_body_type'))";
     }
     
    
     $my_preferred_has_kids = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 448 AND user_id = $my_user_id");
    		if ($my_preferred_has_kids && $my_preferred_has_kids != 'Any' ) $added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 10 AND value = '$my_preferred_has_kids')";
    		
    $my_preferred_wants_kids = xprofile_get_field_data( 451, $my_user_id );
     if ($my_preferred_wants_kids) {
    		$my_preferred_wants_kids = array_slice( $my_preferred_wants_kids, 0, 3 );
    		$my_preferred_wants_kids = join( "%') OR (field_id = 13 AND value LIKE '%",$my_preferred_wants_kids );
    		$my_preferred_wants_kids = "(field_id = 13 AND value LIKE '%" . $my_preferred_wants_kids . "%')";
    		$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE " . $my_preferred_wants_kids . ")";
     }
    
    $my_preferred_marital_status = xprofile_get_field_data( 456, $my_user_id );
    		if ( $my_preferred_marital_status ) {
    			$my_preferred_marital_status = array_slice( $my_preferred_marital_status, 0, 6 );
    			$my_preferred_marital_status = join( "') OR (field_id = 3 AND value = '",$my_preferred_marital_status );
    			$my_preferred_marital_status = "(field_id = 3 AND value = '" . $my_preferred_marital_status . "')";
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE " . $my_preferred_marital_status . ")";
    		}
    		
    $my_preferred_smokes = xprofile_get_field_data( 469, $my_user_id );
    		if ( $my_preferred_smokes ) {
    			$my_preferred_smokes = array_slice( $my_preferred_smokes, 0, 5 );
    			$my_preferred_smokes = join( "') OR (field_id = 160 AND value = '",$my_preferred_smokes );
    			$my_preferred_smokes = "(field_id = 160 AND value = '" . $my_preferred_smokes . "')";
    			$added_args .= " AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE " . $my_preferred_smokes . ")";
    		}
    
    		
    		//Get all matches
    		$my_matches = $wpdb->get_col( $added_args );
    		$include = implode(",", $my_matches);
    		if (!empty($querystring)) $querystring .= '&';
    		$querystring .= 'include=' . $include . '&exclude=1,' . $my_user_id;
    		return $querystring;
    	
    
    } else {
    		global $wpdb;
            if ($object != 'members')  return $querystring;
    		$my_user_id = bp_loggedin_user_id();
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		$i_am_looking_for = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND user_id = $my_user_id");
    	
    		//Get all users that are what the logged_in member is looking for
    		 $my_matches = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender')");
    		$include = implode(",", $my_matches);
    		if (!empty($querystring)) $querystring .= '&';
    		$querystring .= 'include=' . $include . '&exclude=1,' . $my_user_id;
    		return $querystring;
    
    	
    	} 
    }
    add_filter ('bp_ajax_querystring', 'get_desired_users', 20, 2);
    #9560 Reply
    Panos
    Guest

    Haha, I meant sticking not stinking 🙂

    #9561 Reply
    andrea
    Plugin Author

    Panos,

    You are welcome! Great to hear that everything is working now.

Reply to: Sorting my custom members-loop-2 loses the filtering
My Information