钩子文档

get_{$adjacent}_post_join

💡 云策文档标注

概述

此文档介绍 WordPress 中的 get_{$adjacent}_post_join 过滤器,用于修改相邻文章查询的 SQL JOIN 子句。它允许开发者自定义查询逻辑,例如基于分类或排除特定术语。

关键要点

  • 过滤器名称是动态的,基于 $adjacent 参数,可以是 'next' 或 'previous',对应 get_next_post_join 和 get_previous_post_join。
  • 参数包括 $join(JOIN 子句字符串)、$in_same_term(布尔值,指示是否在同一分类术语中)、$excluded_terms(排除的术语 ID 数组或空字符串)、$taxonomy(分类名称)和 $post(WP_Post 对象)。
  • 此过滤器在 get_adjacent_post() 函数中使用,用于检索相邻文章。
  • 从 WordPress 4.4.0 版本开始,添加了 $taxonomy 和 $post 参数;最初在 2.5.0 版本引入。

📄 原文内容

Filters the JOIN 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_join
  • get_previous_post_join

Parameters

$joinstring
The JOIN clause 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_term is true.
$postWP_Post
WP_Post object.

Source

$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post );

Changelog

Version Description
4.4.0 Added the $taxonomy and $post parameters.
2.5.0 Introduced.