BP Profile Search › Use 1 text box and search against 2 field types
-
AuthorPost
-
shanebp
GuestWe’re uses a shortcode form.
We only want to show a single text box.
But we need to search the input across 2 fields: Name, Keywords
Is there a filter I can use to adjust the query so that it searches both Name and Keywords based on the input from a single textbox?
Or if somebody has already asked for this – some example code?
andrea
Plugin AuthorHi shanebp,
You can use the filter ‘bps_field_sql’, see the file bps-xprofile.php.
A possible code sample is:add_filter ('bps_field_sql', 'change_query', 10, 2); function change_query ($sql, $f) { if ($f->id == 5) $sql['where']['field_id'] = 'field_id IN (5,12)'; return $sql; }shanebp
GuestPerfect! Thanks.
filippo
GuestHi Andrea, in your code example what are exactly the values to change? Thanks!
andrea
Plugin AuthorHi Filippo,
If you have field 5 in your search form, and with the field 5 search box you want to search field 5 and field 12 at the same time, you can use the above code unchanged.
Otherwise you can simply replace 5 and 12 with your actual field IDs.
Maria Estevez
GuestHi Andrea, is possible to search in more than two fields? What about seven. I should only put the number of the fields or should I make any other change?
I’m sorry to ask but I’m a newbie…
Thanks!
andrea
Plugin AuthorHi Maria,
You are right, you can simply add the field IDs to the list, e.g. instead of
'field_id IN (5,12)'you can write'field_id IN (5,12,23,43,76)'.Maria Estevez
GuestThank you!
Velli
GuestHi
Thats a great hack 🙂
How can i add standard user IDs like “first_name”, “last_name” and “nickname”?Best regards
Velliandrea
Plugin AuthorHi Velli,
Unfortunately that trick works only with BuddyPress profile fields. Sorry!
-
AuthorPost