BP Profile Search › Modified search query but pagination stays the same
-
AuthorPost
-
Panos
GuestHi Andrea. I uninstalled Paid Memberships Pro since it was causing a conflict with BP Profile Search. I installed S2Member and now I’m good.
Here’s my question. I modified members_loop to only return certain members. For example if the user is a man who is looking for a woman, it will only return women who are looking for a man. Problem is that the pagination still returns all members. When I do a custom search with BP Profile Search it’s still the same result. If a member searches for members in New York only, it will return the correct results but the pagination is still off.
Was what I did the correct way to do it and how can I fix this? Do I modify BP Profile Search? Should I have modified BP Profile Search instead of members_loop?
Any help or pointing me to the right direction would be very helpful.
Thank you!
andrea
Plugin AuthorHi Panos,
Instead of modifying the members-loop.php template file, try using the bp_ajax_querystring filter hook. This is an example:
add_filter ('bp_ajax_querystring', 'modify_directory', 20, 2); function modify_directory ($query_string, $object) { if ($object != 'members') return $query_string; if (the current user is a man) $include = comma-separated list of user IDs of women; else if (the current user is a woman) $include = comma-separated list of user IDs of men; else return $query_string; if (!empty ($query_string)) $query_string .= '&'; $query_string .= 'include='. $include; return $query_string; }Panos
GuestThank you Andrea! I’ll give it a go.
-PanosPanos
GuestAndrea, thanks again. I got this to work. This is the code:
//Only return members that the user wants to see 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"); //In my case, field_id 193 is the Gender field so this will return the logged_in user's gender $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"); //In my case, field_id 197 is the i_am_looking_for field so this will return the logged_in user's desired gender //Get all users that are what the logged_in member is looking for, i.e. if I am a man looking for women, only return women who are looking for men $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 ($query_string)) $query_string .= '&'; $query_string .= 'include='. $include; return $query_string; } add_filter ('bp_ajax_querystring', 'modify_directory', 20, 2);On a bit of a different note, how can I can I make the Hide/Show Custom Search toggle box show underneath or even above the title Custom Search? I’ve tried in the custom CSS this,
div.item-list-tabs bps_header ul li.last {clear: none;}, plus a few variations of it but nothing works. These are two list items that don’t need to float left and right. Just let the natural order happen and have one show under the other. Any ideas?Thanks again for all your help.
-Panosandrea
Plugin AuthorHello Panos,
Thank you for the final code, I’m sure it will help other readers.
On your other question, unfortunately I’m not a CSS expert.
If you don’t succeed in changing the form appearance, you could try to put the form in a sidebar widget (using the Profile Search widget) or even in a page by itself (using the form shortcode).
Another idea could be to override the form template you are using: move the form template to the ‘buddypress/members’ directory in your theme’s root, then change the list elements to DIVs that should be simpler to style.
Panos
GuestNo biggie. Thanks. I’ll play with it. I’m sure I’ll figure it out but it’s low priority right now. I have another question but I’ll ask it separately so it’s easy to find by others with a similar issue.
Thanks again. -
AuthorPost