钩子文档

edit_{$post_type}_per_page

💡 云策文档标注

概述

edit_{$post_type}_per_page 是一个 WordPress 过滤器钩子,用于动态控制特定文章类型在编辑页面每页显示的项目数量。它允许开发者根据文章类型自定义每页显示的帖子数。

关键要点

  • 这是一个动态钩子,$post_type 部分指代文章类型,例如 edit_post_per_page、edit_page_per_page 等。
  • 参数 $posts_per_page 是一个整数,表示每页显示的帖子数量,默认值为 20。
  • 钩子通过 apply_filters 调用,常用于 wp_edit_posts_query() 函数中,以影响编辑页面列表的查询结果。

代码示例

$posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page );

注意事项

  • 钩子自 WordPress 3.0.0 版本引入,使用时需确保兼容性。
  • 动态钩子名称需根据实际文章类型替换 $post_type,例如针对文章类型 'post' 使用 edit_post_per_page。

📄 原文内容

Filters the number of items per page to show for a specific ‘per_page’ type.

Description

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

Possible hook names include:

  • edit_post_per_page
  • edit_page_per_page
  • edit_attachment_per_page

Parameters

$posts_per_pageint
Number of posts to display per page for the given post type. Default 20.

Source

$posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page );

Changelog

Version Description
3.0.0 Introduced.