terms_pre_query
云策文档标注
概述
terms_pre_query 是一个 WordPress 过滤器,用于在 WP_Term_Query 执行查询前拦截并修改术语数组。开发者可以通过此 Hook 自定义术语查询逻辑,或完全绕过默认查询。
关键要点
- 过滤器名称:terms_pre_query,在 WP_Term_Query::get_terms() 中调用。
- 参数:$terms(术语数组或 null)和 $query(WP_Term_Query 实例引用)。
- 功能:返回非 null 值可短路默认查询,返回 null 则允许正常执行。
- 引入版本:WordPress 5.3.0。
代码示例
$this->terms = apply_filters_ref_array( 'terms_pre_query', array( $this->terms, &$this ) );
原文内容
Filters the terms array before the query takes place.
Description
Return a non-null value to bypass WordPress’ default term queries.
Parameters
$termsarray|null-
Return an array of term data to short-circuit WP’s term query, or null to allow WP queries to run normally.
$queryWP_Term_Query-
The WP_Term_Query instance, passed by reference.
Source
$this->terms = apply_filters_ref_array( 'terms_pre_query', array( $this->terms, &$this ) );
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Introduced. |