• Resolved mtharani

    (@mtharani)


    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

    (@dontdream)

    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;
    }
    zo1234

    (@zo1234)

    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

    (@dontdream)

    Hi @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

    (@zo1234)

    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

    (@zo1234)

    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

    (@zo1234)

    Sorry it double-posted

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi @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.

    zo1234

    (@zo1234)

    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.