• Resolved Nifty

    (@niftythree)


    Hi Andrea,

    We want to create a drop down box search where users could, for example, choose to search for another user’s “passion” (e.g. photography, sport, etc.), or could choose an option within the search, labelled “All”, that would show all users (rather than only displaying users with “All” as their “passion”). Let’s say the ID of this field is 18.

    When we run a search as normal and then remove the term selected in the drop down box after “field_18=” from the URL, we get the desired outcome of all users being displayed. It also still respects the selections made from other fields within the same search.

    Is it possible for the search form to do this? 🙂

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Nifty,

    Try adding this code to your bp-custom.php:

    add_action ('bps_field_before_search_form', 'set_placeholder');
    function set_placeholder ($f)
    {
    	if ($f->code == 'field_18' && $f->display == 'selectbox')
    	{
    		$f->options[''] = 'All';
    	}
    }
    Thread Starter Nifty

    (@niftythree)

    Hi Andrea,

    Thanks for getting back to us so quickly!

    We’ve tried the code, but only users who have chosen “All” are shown, rather than every user. Is there anything else we could try? 🙂

    Thanks for your help.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Probably the trick is not to use the word ‘All’ here to avoid possible confusion.

    Try this:

    add_action ('bps_field_before_search_form', 'set_placeholder');
    function set_placeholder ($f)
    {
    	if ($f->code == 'field_18' && $f->display == 'selectbox')
    	{
    		$f->options[''] = 'no filter';    // or any text you choose
    	}
    }
    Thread Starter Nifty

    (@niftythree)

    Hi Andrea,

    We haven’t had any luck with this code either, we’re afraid; it doesn’t seem to be altering the displayed results of any searches.

    Thanks again for your help. 🙂

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Nifty,

    Can you post the URL of your page containing the search form?

    Thread Starter Nifty

    (@niftythree)

    Hi Andrea,

    Here’s the site we’ve been testing it on.

    The profile field we’re testing is “Connection”; it’s the first drop down select box on the home page search. We’re creating a dating site; our hope is that a visitor who comes to the site and doesn’t have a preference over connection type (e.g. long term dating, short term dating, etc.) could search for “Anything” and the search results would show all users, whilst also still respecting the selections made from other fields within the same search (such as gender).

    Thanks.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Nifty,

    Your search field works fine for me as it is. If you don’t want to filter for a specific connection, just leave the field alone (displaying ‘A connection’) and it will return all possible connection types.

    You can change the text ‘A connection’ with the code I posted above. Make sure you write:

    // correct
    $f->options[''] = 'any connection';

    and not:

    // incorrect
    $f->options['any connection'] = 'any connection';

    It’s not possible to add a new option to select all the connection types, because that option is already there (it’s ‘A connection’, or whatever you wish to rename it).

    Thread Starter Nifty

    (@niftythree)

    Hi Andrea,

    You’ve completely got us there! Somehow we missed the obvious solution staring us in the face. 🙂

    Thanks again for your help.

    Plugin Author Andrea Tarantini

    (@dontdream)

    You’re welcome!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Search option for blank field to show all users’ is closed to new replies.