📄 原始资料 | 展开查看原始 JSON(bricks-query_filters-index_post-before.json){ “name”: “bricks/query_filters/index_post/before”, “kind”: “action”, “url”: “https://academy.bricksbuilder.io/developer/hooks/actions/bricks-query_filters-index_post-before/”, “scraped_at”: “2026-08-29”, “hook_name”: “bric…
📄 原始资料 | 展开查看原始 JSON(bricks-query_filters-index_post-before.json)
{
"name": "bricks/query_filters/index_post/before",
"kind": "action",
"url": "https://academy.bricksbuilder.io/developer/hooks/actions/bricks-query_filters-index_post-before/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/query_filters/index_post/before",
"description": {
"en": "Runs before a post is indexed for Query Filters. This action is triggered during the indexing process for a specific post.",
"zh": "在帖子被纳入 Query Filters 索引之前触发。此动作在处理特定帖子的索引过程中触发。"
},
"parameters": [
{
"name": "post_id",
"type": "int",
"type_zh": null,
"description": {
"en": "The ID of the post being indexed.",
"zh": "正在被索引的文章的 ID。"
}
}
],
"example_usage": "add_action( 'bricks/query_filters/index_post/before', function( $post_id ) {\n // Perform actions before indexing a post, e.g., logging or checking conditions\n // error_log( \"Starting indexing for post ID: $post_id\" );\n\n\n // Maybe register custom dynamic data providers if needed for indexing\n} );"
}
前言
在帖子被纳入 Query Filters 索引之前触发。此动作在处理特定帖子的索引过程中触发。
用法
将代码加入子主题的 functions.php:
add_action( 'bricks/query_filters/index_post/before', function( $post_id ) {
// Perform actions before indexing a post, e.g., logging or checking conditions
// error_log( "Starting indexing for post ID: $post_id" );
// Maybe register custom dynamic data providers if needed for indexing
} );
参数
$post_id (int):正在被索引的文章的 ID。
示例代码
官方示例用法
add_action( 'bricks/query_filters/index_post/before', function( $post_id ) {
// Perform actions before indexing a post, e.g., logging or checking conditions
// error_log( "Starting indexing for post ID: $post_id" );
// Maybe register custom dynamic data providers if needed for indexing
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/query_filters/index_post/before', function( $value, $post_id ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。