Bricks 中文文档:bricks/fix_filter_element_db

标签TAGS: 

📎 原始资料  |  下载原始 JSON 文件 (bricks-fix_filter_element_db.json) 前言 Bricks 1.4 引入了 bricks/indexer/run_query 钩子,允许你修改查询筛选索引器的运行查询。 用法 将代码加入子主题的 functions.php: add_filter( ‘bricks/fix_filter_element_db’, function( $handled, $post_id, $template_type ) { // Example: Skip processing for a specific p…

前言

Bricks 1.4 引入了 bricks/indexer/run_query 钩子,允许你修改查询筛选索引器的运行查询。

用法

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

add_filter( 'bricks/fix_filter_element_db', function( $handled, $post_id, $template_type ) {
    // Example: Skip processing for a specific post ID
    if ( $post_id === 1234 ) {
        return true;
    }


    return $handled;
}, 10, 3 );

参数

  • $handled (bool):更新是否已被处理。默认为 false。
  • $post_id (int):正在被处理的文章 ID。
  • $template_type (string):文章的模板类型。

示例代码

筛选返回值

add_filter( 'bricks/fix_filter_element_db', function( $handled, $post_id, $template_type ) {
    // Example: Skip processing for a specific post ID
    if ( $post_id === 1234 ) {
        return true;
    }


    return $handled;
}, 10, 3 );

根据条件短路返回原值

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

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

补充说明

更多细节可参考 官方文档