query_vars
云策文档标注
概述
query_vars 过滤器用于在执行查询前,允许开发者添加、移除或修改公开允许的查询变量。这对于支持自定义重写规则或公开自定义查询变量至关重要。
关键要点
- 过滤器名称:query_vars,在 WP::parse_request() 中调用,用于处理请求中的查询变量。
- 参数:$public_query_vars,一个字符串数组,表示当前允许的查询变量名列表。
- 用途:通过此过滤器,开发者可以扩展 WordPress 的查询能力,例如添加自定义参数以配合重写规则。
代码示例
function myplugin_query_vars( $qvars ) {
$qvars[] = 'custom_query_var';
return $qvars;
}
add_filter( 'query_vars', 'myplugin_query_vars' );
原文内容
Filters the query variables allowed before processing.
Description
Allows (publicly allowed) query vars to be added, removed, or changed prior to executing the query. Needed to allow custom rewrite rules using your own arguments to work, or any other custom query variables you want to be publicly available.
Parameters
$public_query_varsstring[]-
The array of allowed query variable names.
Source
$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |