Query works in phpMyAdmin but not through BP
-
Hi all,
I use the below code to modify the member directory and only return a user’s matches. For example, if I’m a man looking for a Woman the directory will default to only showing all Women who are looking for a Man.function modify_directory ($query_string, $object) { global $wpdb; if ($object != 'members') return $query_string; $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 THIS RETURNS NOTHING $my_matches = array($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 ($query_string)) $query_string .= '&'; $query_string .= 'include='. $include; return $query_string; } add_filter ('bp_ajax_querystring', 'modify_directory', 20, 2);
The problem is that $my_matches returns nothing. i.e.
echo $my_matches[0]
outputs Array.When I run
Select user_id from wp_bp_xprofile_data where field_id = 197 and value = ‘Man’ and user_id in (select user_id from wp_bp_xprofile_data where field_id = 193 and value = ‘Woman’)
in phpMyAdmin it works, but when this runs in here it doesn’t work.Another note: This:
echo "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')" . ' -- $matches[0]= '. $matches[0];
returns this:SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 193 AND value = 'Woman' AND user_id IN (SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 197 AND value = 'Man') -- $my_matches[0]= Array
Any ideas?
Thank you in advance.
-Panos
- You must be logged in to reply to this topic.