Pre populate the location field

BP Profile Search Pre populate the location field

  • Author
    Post
  • #11917 Reply
    Alex
    Guest

    Hi 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,
    Alex

    #11918 Reply
    andrea
    Plugin Author

    Hi 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.

    #11919 Reply
    Alex
    Guest

    Hi 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,
    Alex

    #11920 Reply
    andrea
    Plugin Author

    Hi Alex,

    Yes that’s possible, please have a look at bullet 2. in:

    https://dontdream.it/bp-profile-search-5-3/

Reply to: Pre populate the location field
My Information