Support

Account

Home Forums Front-end Issues ACF Google Maps output

Unread

ACF Google Maps output

  • I’ve seen a few posts on this but none nail what I need.

    I’m trying to output the address from the Google Map field, so far I’ve used;

    $location = get_field('address', 'options');
    if( $location ) {
    
        // Loop over segments and construct HTML.
        $address = '';
        foreach( array('street_number', 'street_name', 'city', 'state', 'post_code', 'country') as $i => $k ) {
            if( isset( $location[ $k ] ) ) {
                $address .= sprintf( '<span class="segment-%s">%s</span><br>', $k, $location[ $k ] );
            }
        }
    
        // Trim trailing comma.
        $address = trim( $address, ', ' );
    
        // Display HTML.
        echo '<p>' . $address . '</p>';
    }

    Which outputted it as;
    6
    David Lane
    England
    NG6 0JU
    United Kingdom

    However, I need it to output for the UK as;
    6 David Lane
    Nottingham
    NG6 0JU
    United Kingdom

    Anyone work out why Nottingham isn’t showing and 6 has it’s own line?

Viewing 1 post (of 1 total)

The topic ‘ACF Google Maps output’ is closed to new replies.