Bricks 中文文档:bricks/dynamic_data/meta_value/{meta_key}

📎 原始资料  |  下载原始 JSON 文件 (bricks-dynamic_data-meta_value-meta_key.json) 前言 筛选动态数据选择器面板中显示的标签分组顺序。可用于更改标签在动态数据选择器中显示的顺序。 用法 将代码加入子主题的 functions.php: // Filter the value of the custom field with key ‘my_price_field’ add_filter( ‘bricks/dynamic_data/meta_value/my_price_field’, function( $value…

前言

筛选动态数据选择器面板中显示的标签分组顺序。可用于更改标签在动态数据选择器中显示的顺序。

用法

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

// Filter the value of the custom field with key 'my_price_field'
add_filter( 'bricks/dynamic_data/meta_value/my_price_field', function( $value, $post ) {
    // Example: Format the price
    return '$' . number_format( (float) $value, 2 );
}, 10, 2 );

参数

  • $value (mixed):自定义字段的值。
  • $post (WP_Post):文章对象。

示例代码

筛选返回值

// Filter the value of the custom field with key 'my_price_field'
add_filter( 'bricks/dynamic_data/meta_value/my_price_field', function( $value, $post ) {
    // Example: Format the price
    return '$' . number_format( (float) $value, 2 );
}, 10, 2 );

根据条件短路返回原值

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

add_filter( 'bricks/dynamic_data/meta_value/{meta_key}', function( $value, $value ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档