Title: Search Across Multiple Fields
Last modified: October 29, 2016

---

# Search Across Multiple Fields

 *  Resolved [mtharani](https://wordpress.org/support/users/mtharani/)
 * (@mtharani)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/search-across-multiple-fields/)
 * Apologies if this has been covered before. Right now, we have extra fields that
   allow users to specify the species and breed of pet they have, from a selection
   of taxonomy items. Due to limitations of BuddyPress, we have up to 4 identical“
   Pet #1”, “Pet #2”, etc. groupings of fields so people can specify more than one
   pet. Using this plugin, we’d like to be able to have a user select “Dog” and “
   Chihuahua” and have that pull any users who selected “Dog” or “Chihuahua” in 
   either of the 4 Species fields or 4 Breeds fields, respectively. Is that possible
   with this plugin? Even if it requires making some code changes, it’s fine. We’re
   only using it for this singular purpose to connect users based on the type of
   animal they have.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-8460301)
 * Hi mtharani,
 * Sorry for the late reply. You can use the filter ‘bps_field_sql’, see the file
   _bps-xprofile.php_, line 139. A possible code snippet is:
 *     ```
       add_filter ('bps_field_sql', 'change_query', 10, 2);
       function change_query ($sql, $f)
       {
               if ($f->id == 10)  $sql['where']['field_id'] = 'field_id IN (10,12)';
               return $sql;
       }
       ```
   
    -  This reply was modified 9 years, 6 months ago by [Andrea Tarantini](https://wordpress.org/support/users/dontdream/).
 *  [zo1234](https://wordpress.org/support/users/zo1234/)
 * (@zo1234)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9117544)
 * I’m having this issue as well. Can you tell us where exactly to put the code?
   Does it need to replace the other code, etc. I tried adding it stand-alone and
   it didn’t fix it. Thanks.
 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9119325)
 * Hi [@zo1234](https://wordpress.org/support/users/zo1234/),
 * You can add the above code in your _bp-custom.php_ file. Of course you have to
   replace `10` with the field ID of the field that appears in your search form,
   and the list `10,12` with the list of the field IDs that are to be searched.
 *  [zo1234](https://wordpress.org/support/users/zo1234/)
 * (@zo1234)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9120083)
 * Thanks for response!
    Crap, I think I phrased what I said wrong, sorry I don’t
   know much about PHP. I think I meant how to search across multiple Field Groups,
   or is the solution similar?
 * I have this issue:
 * – I have multiple Field Groups (tabbed)
    – The content of Field Groups is duplicate
   content, only the Field Group name is different.
 * For example
 * User Profile
 *  **Field Groups**
 *  > Info
    – Name – About
 *  > Player Card 1
    – Height – Weight
 *  > Player Card 2
    – Height – Weight
 * Is there a specific code to make sure searches include “Height” and “Weight” 
   for BOTH Field Groups? Reason is this would save space, etc. instead of including“
   Player 1” and “Player 2” in search form. Thank you!
 *  [zo1234](https://wordpress.org/support/users/zo1234/)
 * (@zo1234)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9120166)
 * Thanks for response!
    I think I phrased what I said wrong, sorry I don’t know
   much about PHP. I think I meant how to search across multiple Field Groups, or
   is the solution similar?
 * I have this issue:
 * – I have multiple Field Groups (tabbed)
    – The content of Field Groups is duplicate
   content, only the Field Group name is different.
 * For example
 * User Profile
 *  Field Groups
 *  > Info
    – Name – About
 *  > Player Card 1
    – Height – Weight
 *  > Player Card 2
    – Height – Weight
 * Is there a specific code to make sure searches will include “Height” and “Weight”
   for BOTH “Player 1” and “Player 2” Field Groups? So that one search for “Height”
   spans multiple fields. Reason is this would save space, etc. instead of including“
   Player 1” and “Player 2” in search form. Thank you!
 *  [zo1234](https://wordpress.org/support/users/zo1234/)
 * (@zo1234)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9120544)
 * Sorry it double-posted
 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9120777)
 * Hi [@zo1234](https://wordpress.org/support/users/zo1234/),
 * Yes, the solution is the one posted above. If, for instance, your field IDs are
   as follows:
 * > Player Card 1
    – Height (ID 10) – Weight (ID 11)
 * > Player Card 2
    – Height (ID 12) – Weight (ID 13)
 * you have to add this code to your _bp-custom.php_ file:
 *     ```
       add_filter ('bps_field_sql', 'change_query', 10, 2);
       function change_query ($sql, $f)
       {
               if ($f->id == 10)  $sql['where']['field_id'] = 'field_id IN (10,12)';
               if ($f->id == 11)  $sql['where']['field_id'] = 'field_id IN (11,13)';
               return $sql;
       }
       ```
   
 * In your search form, you’ll specify only the fields with ID 10 and 11, but the
   search will work for the other fields too, as intended.
    -  This reply was modified 9 years ago by [Andrea Tarantini](https://wordpress.org/support/users/dontdream/).
 *  [zo1234](https://wordpress.org/support/users/zo1234/)
 * (@zo1234)
 * [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9122548)
 * This worked, thanks alot appreciate it!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Search Across Multiple Fields’ is closed to new replies.

 * ![](https://ps.w.org/bp-profile-search/assets/icon.svg?rev=1568973)
 * [BP Profile Search](https://wordpress.org/plugins/bp-profile-search/)
 * [Support Threads](https://wordpress.org/support/plugin/bp-profile-search/)
 * [Active Topics](https://wordpress.org/support/plugin/bp-profile-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bp-profile-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bp-profile-search/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [zo1234](https://wordpress.org/support/users/zo1234/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/search-across-multiple-fields/#post-9122548)
 * Status: resolved