钩子文档

nav_menu_items_{$post_type_name}_recent

💡 云策文档标注

概述

nav_menu_items_{$post_type_name}_recent 是一个 WordPress 过滤器钩子,用于修改在菜单项元框的“最近”选项卡中显示的帖子列表。它允许开发者自定义特定文章类型的最近文章查询结果。

关键要点

  • 这是一个动态钩子,钩子名称中的 $post_type_name 部分对应文章类型名称,例如 nav_menu_items_post_recent 用于文章类型“post”。
  • 钩子接收四个参数:$most_recent(WP_Post 对象数组)、$args(WP_Query 参数数组)、$box(传递给 wp_nav_menu_item_post_type_meta_box() 的参数数组)和 $recent_args(“最近”选项卡的 WP_Query 参数数组)。
  • 钩子主要用于 wp_nav_menu_item_post_type_meta_box() 函数中,影响后台菜单管理界面的显示。
  • 从 WordPress 4.9.0 版本开始添加了 $recent_args 参数,4.3.0 版本引入此钩子。

代码示例

$most_recent = apply_filters(
    "nav_menu_items_{$post_type_name}_recent",
    $most_recent,
    $args,
    $box,
    $recent_args
);

📄 原文内容

Filters the posts displayed in the ‘Most Recent’ tab of the current post type’s menu items meta box.

Description

The dynamic portion of the hook name, $post_type_name, refers to the post type name.

Possible hook names include:

  • nav_menu_items_post_recent
  • nav_menu_items_page_recent

Parameters

$most_recentWP_Post[]
An array of post objects being listed.
$argsarray
An array of WP_Query arguments for the meta box.
$boxarray
Arguments passed to wp_nav_menu_item_post_type_meta_box().
$recent_argsarray
An array of WP_Query arguments for ‘Most Recent’ tab.

Source

$most_recent = apply_filters(
	"nav_menu_items_{$post_type_name}_recent",
	$most_recent,
	$args,
	$box,
	$recent_args
);

Changelog

Version Description
4.9.0 Added the $recent_args parameter.
4.3.0 Introduced.