【问题标题】:How to remove latitude and longitude from Google Maps ACF field in Wordpress?如何从 Wordpress 中的 Google Maps ACF 字段中删除纬度和经度?
【发布时间】:2015-04-21 21:58:56
【问题描述】:

在 Wordpress 中,有一个高级自定义字段 Google 地图选项。我用它来将地址作为文本引用。使用的代码:

<?php the_field('address');?>

地址是谷歌地图的自定义变量。

这显示街道、城市、州、邮政编码、国家和纬度和经度。

我不需要国家,无论经纬度。我一直在尝试找到一个可以编辑的数组,但到目前为止还没有运气。

谢谢!

【问题讨论】:

    标签: php wordpress google-maps


    【解决方案1】:

    如果您使用get_field() 而不是the_field(),它将为您提供一个包含 3 个元素的数组:address、lat 和 lng .

    不幸的是,address 是一个包含完整地址的字符串,包括国家名称。 但如果它始终是用逗号分隔的最后一个声音,您可以只检索地址字符串,直到最后一个逗号,如下所示:

    $location = get_field('address');
    if(isset($location['address'])) {
        $address = substr($location['address'], 0, strrpos($location['address'], ','));
        echo $address;
    }
    

    【讨论】:

    • 很好,我很高兴:)。请点击复选标记考虑accepting the answer。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
    • 啊,谢谢。我刚从这里开始,所以我还不知道那个选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    相关资源
    最近更新 更多