在前端显示acf map字段

Display acf map field in the front end

如何使用高级自定义字段仅在前端显示地图?

我查看了文档,它没有显示仅显示特定字段的方法。

将此添加到您的 functions.php

function my_acf_google_map_api( $api ){

    $api['key'] = 'xxx';

    return $api;

 }

add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');

这将启用 google 地图 api。

    <?php $location = get_field('location'); if( !empty($location) ):?>
        <div class="acf-map">
            <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
            </div>
        </div>
    <?php endif; ?>

确保将 位置 更改为 get_field 地图字段的名称。

ACF 地图页面中均有记载:https://www.advancedcustomfields.com/resources/google-map/