Title: default value
Last modified: August 24, 2021

---

# default value

 *  Resolved [netreneris](https://wordpress.org/support/users/netreneris/)
 * (@netreneris)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/default-value-14/)
 * Hello Andrea,
 * how are you? I have a problem and I hope that you could help me. I want to add
   a default value to the field “location”, but just in the “enter range” box. Now
   it’s set to “5”, but it repeats in both boxes – in the range box and in google
   location search box.
 * I’m using this code snippet:
 *     ```
       add_action ('bps_field_before_search_form', 'set_default');
       function set_default ($f)
       {
       	if ($f->code == 'field_776')    // replace 34 with your field ID
       	{
       		// assign the default value
       		$f->value = 5;
       	}
       }
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdefault-value-14%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/default-value-14/#post-14803232)
 * Hello netreneris,
 * In your case the code is as follows:
 *     ```
       add_action ('bps_field_before_search_form', 'set_defaults');
       function set_defaults ($f)
       {
       	if ($f->code == 'field_776' && $f->display == 'distance')
       	{
       		$f->value['distance'] = 5;
       		$f->value['units'] = 'miles';
       	}
       }
       ```
   
 *  Thread Starter [netreneris](https://wordpress.org/support/users/netreneris/)
 * (@netreneris)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/default-value-14/#post-14803744)
 * Thank you very much, it’s working!
 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/default-value-14/#post-14818156)
 * Great, you’re welcome!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘default value’ is closed to new replies.

 * ![](https://ps.w.org/bp-profile-search/assets/icon.svg?rev=1568973)
 * [BP Profile Search](https://wordpress.org/plugins/bp-profile-search/)
 * [Support Threads](https://wordpress.org/support/plugin/bp-profile-search/)
 * [Active Topics](https://wordpress.org/support/plugin/bp-profile-search/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bp-profile-search/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bp-profile-search/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/default-value-14/#post-14818156)
 * Status: resolved