search results for contain

BP Profile Search › search results for contain

  • Author
    Post
  • #8661 Reply
    liz
    Guest

    Hi

    We use your plugin to search through member profiles, which use a separate profile field for names.

    If someone has a middle name, the search doesn’t return results if the middle name is missing from the search terms i.e. name = John David Jones, search for ‘John Jones’ gives no results.

    Any other permutation does give results – bit odd!

    Search mode is set to contain, any help would be greatly appreciated!

    Thanks

    #8675 Reply
    andrea
    Plugin Author

    Hi Liz,

    In your case, you have to set the text search mode to is like, and search for %John%Jones% (see the Text Search Mode section here).

    If you prefer to add some custom code to your site instead, please let me know and I’ll try to think of something.

    #8679 Reply
    liz
    Guest

    Hi Andrea

    Our visitors are very unlikely to do this. If you could have a look at it and create some custom code that would be great.

    Thank you so much!

    #8687 Reply
    andrea
    Plugin Author

    Hi Liz,

    You can add this code to your functions.php or bp-custom.php file:

    add_filter ('bps_before_search', 'change_search');
    function change_search ($f)
    {
    	if ($f->code == 'field_1' && $f->filter == '')
    	{
    		$f->filter = 'like';
    		$f->value = str_replace (' ', '%', $f->value);
    		$f->values = (array)$f->value;
    	}
    	return $f;
    }

    I assume the names are in the field_1, otherwise you can replace field_1 with field_xyz, where xyz is the field ID.

    #8712 Reply
    liz
    Guest

    Hi Andrea

    Got it to work, thank you for all your help.

    #8715 Reply
    andrea
    Plugin Author

    Great, you are welcome!

Reply to: search results for contain
My Information