get_{$adjacent}_post_where
云策文档标注
概述
此文档介绍 WordPress 中的 get_{$adjacent}_post_where 过滤器钩子,用于修改相邻文章查询的 SQL WHERE 子句。钩子名称动态部分 $adjacent 可指定为 'next' 或 'previous',对应 get_next_post_where 和 get_previous_post_where。
关键要点
- 过滤器钩子:get_{$adjacent}_post_where,动态生成钩子名称。
- 功能:过滤相邻文章查询的 SQL WHERE 子句,允许开发者自定义查询条件。
- 参数:包括 $where(WHERE 子句字符串)、$in_same_term(是否在同一分类术语中)、$excluded_terms(排除的术语 ID 数组)、$taxonomy(分类法名称)和 $post(WP_Post 对象)。
- 相关函数:与 get_adjacent_post() 函数配合使用,用于检索相邻文章。
- 版本变更:6.9.0 版本添加了基于 ID 的回退机制处理相同日期的文章;4.4.0 版本新增 $taxonomy 和 $post 参数;2.5.0 版本引入此钩子。
代码示例
$where = apply_filters( "get_{$adjacent}_post_where", $where_prepared, $in_same_term, $excluded_terms, $taxonomy, $post );
原文内容
Filters the WHERE clause in the SQL for an adjacent post query.
Description
The dynamic portion of the hook name, $adjacent, refers to the type of adjacency, ‘next’ or ‘previous’.
Possible hook names include:
get_next_post_whereget_previous_post_where
Parameters
$wherestring-
The
WHEREclause in the SQL. $in_same_termbool-
Whether post should be in the same taxonomy term.
$excluded_termsint[]|string-
Array of excluded term IDs. Empty string if none were provided.
$taxonomystring-
Taxonomy. Used to identify the term used when
$in_same_termis true. $postWP_Post-
WP_Post object.
Source
$where = apply_filters( "get_{$adjacent}_post_where", $where_prepared, $in_same_term, $excluded_terms, $taxonomy, $post );