Bricks 中文文档:bricks/acf/google_map/address_parts

标签TAGS: 

📎 原始资料  |  下载原始 JSON 文件 (bricks-acf-google_map-address_parts.json) 前言 筛选渲染 ACF Google Map 字段时所显示地址的组成部分。可用于重新排序或移除地址中的特定部分。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/acf/google_map/address_parts’, function( $address_parts, $value, $field ) { // Example: Only show city and country, an…

前言

筛选渲染 ACF Google Map 字段时所显示地址的组成部分。可用于重新排序或移除地址中的特定部分。

用法

将代码加入子主题的 functions.php

add_filter( 'bricks/acf/google_map/address_parts', function( $address_parts, $value, $field ) {
    // Example: Only show city and country, and change order
    return [ 'city', 'country' ];
}, 10, 3 );

参数

  • $address_parts (array):地址部分键的数组。默认值:[‘street_name’, ‘street_number’, ‘city’, ‘state’, ‘post_code’, ‘country’]。
  • $value (array):ACF Google Map 字段的原始值。
  • $field (array):ACF 字段设置。

示例代码

筛选返回值

add_filter( 'bricks/acf/google_map/address_parts', function( $address_parts, $value, $field ) {
    // Example: Only show city and country, and change order
    return [ 'city', 'country' ];
}, 10, 3 );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/acf/google_map/address_parts', function( $value, $address_parts ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档