Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 18, 2023 14:44
Show Gist options
  • Save zackpyle/f910711fba08f4cbef9a121c788051d7 to your computer and use it in GitHub Desktop.
Save zackpyle/f910711fba08f4cbef9a121c788051d7 to your computer and use it in GitHub Desktop.
ACF Google Address Field Shortcode #acf
<?php
// ACF Google Map Field -> Address Shortcode
add_shortcode( 'acf_address' , function( $atts ) {
if (!function_exists('get_field') ) return '';
$atts = shortcode_atts( array( 'field' => false , 'sub' => 'address' ) , $atts, $shortcode = 'acf_address' );
if ($atts[ 'field' ] && $map = get_field( $atts[ 'field'] ) ) {
if ( isset( $map[ $atts['sub'] ] ) ) return $map[ $atts['sub'] ];
}
return '[ something went wrong ]';
} );
/*
[acf_address field="FIELD_NAME" sub="address"]
Fields you can pull:
address
lat
lng
zoom
place_id
street_number
street_name
street_name_short
city
state
state_short
post_code
country
country_short
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment