Custom xprofile field instead of username on map and multiple address fields

I am using the Buddypress profile map addon for the Google Maps plugin and my client is needing a custom profile field to be displayed on the map instead of the username.

I am also needing to use multiple address fields (street address, city, state, zip) and I am using this code in wp-config.php:

define('AGM_BP_PROFILE_MAP_USE_ADDRESS_FIELDS', 'Street Address,City,State,Zip Code', true);

Google Maps will place the marker in the right spot, but it will only show the street address when you click on it. I need help showing the full address.

Any help is greatly appreciated.

  • Vladislav
    • Dead Eye Dev

    Hello,

    You can achieve this by hooking up to the agm_google_maps-bp_profile_map-location_markup filter. It will be passed on the markup used for the location marker and it'll also be improved in the future plugin releases. Please, note that your user locations are cached between their address changes, so you will also need to rebuild your profile maps.

  • dean_schulz1
    • WPMU DEV Initiate

    I hate to take up too much of your time, but would it be possible to give me the exact code I need to put into my functions.php file?

    I'm trying to display the 'Church Name' xprofile field that I created instead of the username.

    I really appreciate it!

  • dean_schulz1
    • WPMU DEV Initiate

    Somehow I figured it out. I found this bit of code on another site and it worked great to display multiple address fields and somehow my custom name field as well (not sure how it's doing that). Anyway, so happy to have it figured out! I hope this helps someone else as well. :wink:

    function agm_multiple_bp_profile_fields ($old_address, $user_id) {
    	$city = bp_get_profile_field_data(array(
    		'field' => '18', // Field name or ID
    		'user_id' => $user_id,
    	));
    	$street = bp_get_profile_field_data(array(
    		'field' => '15', // Field name or ID
    		'user_id' => $user_id,
    	));
            $state = bp_get_profile_field_data(array(
    		'field' => '20', // Field name or ID
    		'user_id' => $user_id,
    	));
            $zip = bp_get_profile_field_data(array(
    		'field' => '19', // Field name or ID
    		'user_id' => $user_id,
    	));
    	$address = sprintf("%s %s, %s", $street, $city, $state, $zip);
    	return $address;
    }
    add_filter("agm_google_maps-bp_profile_map-user_address", "agm_multiple_bp_profile_fields", 10, 2);
  • dean_schulz1
    • WPMU DEV Initiate

    Actually, I realized that another plugin I'm using called "BuddyPress Real Names" is the real cause of displaying my custom profile field. I installed it a while ago and didn't realize that I needed to rebuild the BuddyPress profile maps in order to repopulate the data. The above code only displays and utilized multiple address fields.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.