the_search_query
云策文档标注
概述
the_search_query 是一个 WordPress 过滤器,用于修改搜索查询变量的内容以便显示。它通常与 the_search_query() 函数结合使用。
关键要点
- the_search_query 是一个过滤器钩子,允许开发者过滤搜索查询变量的内容。
- 参数 $search 是搜索查询变量的内容,类型为 mixed。
- 该过滤器自 WordPress 2.3.0 版本引入。
代码示例
echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );注意事项
- 使用时需注意安全性,建议结合 esc_attr() 等函数进行转义。
- 该过滤器主要用于显示目的,不影响实际的搜索逻辑。
原文内容
Filters the contents of the search query variable, for display.
Parameters
$searchmixed-
Contents of the search query variable.
Source
echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |