Default Value for Drop Down / Location

BP Profile Search › Default Value for Drop Down / Location

  • Author
    Post
  • #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
    Plugin Author

    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.

Reply to: Default Value for Drop Down / Location
My Information