【发布时间】:2021-12-30 23:11:07
【问题描述】:
这里是 PHP 新手...我正在尝试显示 ACF Google 地图字段的地址。
我认为以下代码会将地址显示为:123 Main Street, Charlotte, NC 28216, USA 但没有返回任何内容。
<?php
$map_location = get_field('location');
echo $map_location['location'];
?>
我能够让它工作,但它在门牌号后面加一个逗号,在邮政编码后面加一个句点,这看起来有点奇怪。前任。 123, Main Street, Charlotte, North Carolina, 28216。
<?php
$map_location = get_field('location');
if( $map_location ) {
// Loop over segments and construct HTML.
$address = '';
foreach( array('street_number', 'street_name', 'city', 'state', 'post_code') as $i => $k ) {
if( isset( $map_location[ $k ] ) ) {
$address .= sprintf( '<span class="segment-%s">%s</span>, ', $k, $map_location[ $k ] );
}
}
// Trim trailing comma.
$address = trim( $address, ', ' );
// Display HTML.
echo '<p>' . $address . '.</p>';
}
?>
有谁知道如何将 ACF 谷歌地图地址回显为 123 Main Street, Charlotte, North Carolina, 28216?
【问题讨论】:
标签: php google-maps advanced-custom-fields