BP Profile Search › Pre populate the location field
-
AuthorPost
-
Alex
GuestHi Andrea,
I’m using the BP xProfile Location and would like to know how I set the default in the form to what the user has entered in their profile.
Thanks,
Alexandrea
Plugin AuthorHi Alex,
You can add this code to your bp-custom.php file:
add_action ('bps_field_before_search_form', 'set_default_location'); function set_default_location ($f) { global $wpdb; if ($f->code != 'field_37' || $f->display != 'distance') return; // replace 37 with your field ID $user = bp_loggedin_user_id (); if (empty ($user)) return; $table_name = $wpdb->prefix. 'bds_locations'; $query = "SELECT * FROM $table_name WHERE user_id = $user AND field_id = 37;"; // replace 37 with your field ID $value = $wpdb->get_row ($query); if (!empty ($value)) { $f->value['location'] = $value->location; $f->value['lat'] = $value->lat; $f->value['lng'] = $value->lng; } }
Replace 37 with the actual field ID of your profile location field.
Alex
GuestHi Andrea,
That’s great, if that is possible is it possible to set the default of any of the profile fields and if so how is that done?
Thanks,
Alexandrea
Plugin AuthorHi Alex,
Yes that’s possible, please have a look at bullet 2. in:
-
AuthorPost