Bricks 中文文档:bricks/filter_element/count_source_wcField

📎 原始资料  |  下载原始 JSON 文件 (bricks-filter_element-count_source_wcField.json) 前言 此筛选器允许你修改 Bricks 页头的最终 HTML 输出。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/filter_element/count_source_wcField’, function( $count_source, $element ) { // Example: Hide counts for rating filter by setting them…

前言

此筛选器允许你修改 Bricks 页头的最终 HTML 输出。

用法

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

add_filter( 'bricks/filter_element/count_source_wcField', function( $count_source, $element ) {
    // Example: Hide counts for rating filter by setting them to 0 (if logic hides 0 counts)
    // Or manipulate them for specific ratings
    return $count_source;
}, 10, 2 );

参数

  • $count_source (array):关联数组,键为筛选值,值为对应的计数。
  • $element (object):筛选元素实例。

示例代码

筛选返回值

add_filter( 'bricks/filter_element/count_source_wcField', function( $count_source, $element ) {
    // Example: Hide counts for rating filter by setting them to 0 (if logic hides 0 counts)
    // Or manipulate them for specific ratings
    return $count_source;
}, 10, 2 );

根据条件短路返回原值

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

add_filter( 'bricks/filter_element/count_source_wcField', function( $value, $count_source ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档