Default Value for Drop Down / Location

Home Forums BP Profile Search Forum Default Value for Drop Down / Location

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #11274 Reply
    luke
    Guest

    I have seen on here how to default a value in a text field, but have not been able to figure out how to do so with:

    a) A dropdown list

    and

    b) The distance[distance] value in your location search.

    Are you able to instruct me on how to do so?

    #11276 Reply
    andrea
    Keymaster

    Hello luke,

    You can add the following code to your bp-custom.php:

    add_action ('bps_field_before_search_form', 'set_defaults');
    function set_defaults ($f)
    {
    	if ($f->code == 'field_5')   // drop-down field
    	{
    		$f->value = 'Canada';
    	}
    	if ($f->code == 'field_10')   // location field
    	{
    		$f->value['distance'] = 5;
    		$f->value['units'] = 'miles';
    	}
    }

    Replace 5 and 10 with the actual IDs of your fields.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Default Value for Drop Down / Location
Your information: