钩子文档

posts_selection

💡 云策文档标注

概述

posts_selection 是一个 WordPress 动作钩子,在查询执行前触发,用于宣布查询的当前选择参数。主要供缓存插件使用,以获取查询字符串信息。

关键要点

  • 触发时机:在查询执行前触发,传递组装好的查询字符串。
  • 主要用途:专为缓存插件设计,用于获取查询参数以优化缓存策略。
  • 参数说明:传递一个字符串参数 $selectionstring,包含组装后的查询(如 WHERE、GROUP BY、ORDER BY、LIMITS、JOIN 等部分)。
  • 注意事项:该字符串不是引用传递,修改它不会影响实际查询。
  • 相关函数:在 WP_Query::get_posts() 中调用,用于检索基于查询变量的文章数组。
  • 版本历史:自 WordPress 2.3.0 版本引入。

代码示例

do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );

注意事项

此钩子传递的查询字符串是只读的,任何修改都不会改变实际查询行为,因此仅适用于信息获取或缓存处理。


📄 原文内容

Fires to announce the query’s current selection parameters.

Description

For use by caching plugins.

Parameters

$selectionstring
The assembled selection query.

More Information

This action hook is executed prior to the query and is passed a string containing the assembled query. Note that this string is NOT passed by reference and manipulating this string will not affect the actual query. This is intended to be used primarily by caching plugins.

Source

do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );

Changelog

Version Description
2.3.0 Introduced.