Last active
May 18, 2023 14:44
-
-
Save zackpyle/f910711fba08f4cbef9a121c788051d7 to your computer and use it in GitHub Desktop.
ACF Google Address Field Shortcode #acf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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