Use 1 text box and search against 2 field types

Home Forums BP Profile Search Forum Use 1 text box and search against 2 field types

This topic contains 9 replies, has 2 voices, and was last updated by  andrea 4 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #8642 Reply

    shanebp

    We’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?

    #8644 Reply

    andrea
    Keymaster

    Hi 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;
    }
    
    #8645 Reply

    shanebp

    Perfect! Thanks.

    #9337 Reply

    filippo

    Hi Andrea, in your code example what are exactly the values to change? Thanks!

    #9339 Reply

    andrea
    Keymaster

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

    #9718 Reply

    Maria Estevez

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

    #9719 Reply

    andrea
    Keymaster

    Hi 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)'.

    #9720 Reply

    Maria Estevez

    Thank you!

    #9753 Reply

    Velli

    Hi

    Thats a great hack 🙂
    How can i add standard user IDs like “first_name”, “last_name” and “nickname”?

    Best regards
    Velli

    #9754 Reply

    andrea
    Keymaster

    Hi Velli,

    Unfortunately that trick works only with BuddyPress profile fields. Sorry!

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: Use 1 text box and search against 2 field types
Your information: