search in two fields

BP Profile Search › search in two fields

  • Author
    Post
  • #12443 Reply
    Pelle
    Guest

    I have a group of members who sometimes work at two clinics. Therefore, I have a need to perform searches that look for the postal code of both Clinic 1 and Clinic 2.

    I have tried adding a filter to functions.php, but nothing works. My searches only show results from Clinic 1.

    Do you have an example of how I can search in two fields? Any advice is welcome.

    Best regards,
    Pelle

    #12444 Reply
    andrea
    Plugin Author

    Hi Pelle,

    Let’s say the field IDs of Clinic 1 and Clinic 2 are 50 and 60.

    You can build your search form using Clinic 1 only, then you can add this code to your bp-custom.php file:

    add_filter ('bps_field_sql', 'search_two_fields', 10, 2);
    function search_two_fields ($sql, $f)
    {
    	if ($f->code == 'field_50')
    	{
    		$sql['where']['field_id'] = 'field_id IN (50, 60)';
    	}
    	return $sql;
    }

    Replace 50 and 60 with the actual field IDs of your Clinic 1 and Clinic 2 fields.

Reply to: search in two fields
My Information