📄 原始资料 | 展开查看原始 JSON(bricks-query-supress_render_content.json){ “name”: “bricks/query/supress_render_content”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-query-supress_render_content/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/query/…
📄 原始资料 | 展开查看原始 JSON(bricks-query-supress_render_content.json)
{
"name": "bricks/query/supress_render_content",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-query-supress_render_content/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/query/supress_render_content",
"description": {
"en": "Determines whether to suppress the rendering of the query loop content. This is used by the “Live Search” feature to prevent rendering initial results on page load if they are going to be immediately replaced by AJAX results.",
"zh": "确定是否应抑制查询循环内容的渲染。由“实时搜索(Live Search)”功能使用,以防止在页面加载时渲染初始结果(如果它们将立即被 AJAX 结果替换)。"
},
"parameters": [
{
"name": "suppress",
"type": "bool",
"type_zh": null,
"description": {
"en": "Whether to suppress rendering.",
"zh": "是否抑制渲染。"
}
},
{
"name": "query",
"type": "object",
"type_zh": null,
"description": {
"en": "The Bricks Query instance.",
"zh": "Bricks 查询实例。"
}
}
],
"example_usage": "add_filter( 'bricks/query/supress_render_content', function( $suppress, $query ) {\n // Example: Suppress content rendering for a specific query ID on mobile devices\n if ( $query->id === 'heavy_query' && wp_is_mobile() ) {\n return true;\n }\n\n\n return $suppress;\n}, 10, 2 );"
}
前言
确定是否应抑制查询循环内容的渲染。由“实时搜索(Live Search)”功能使用,以防止在页面加载时渲染初始结果(如果它们将立即被 AJAX 结果替换)。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/query/supress_render_content', function( $suppress, $query ) {
// Example: Suppress content rendering for a specific query ID on mobile devices
if ( $query->id === 'heavy_query' && wp_is_mobile() ) {
return true;
}
return $suppress;
}, 10, 2 );
参数
$suppress (bool):是否抑制渲染。
$query (object):Bricks 查询实例。
示例代码
筛选返回值
add_filter( 'bricks/query/supress_render_content', function( $suppress, $query ) {
// Example: Suppress content rendering for a specific query ID on mobile devices
if ( $query->id === 'heavy_query' && wp_is_mobile() ) {
return true;
}
return $suppress;
}, 10, 2 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/query/supress_render_content', function( $value, $suppress ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。