钩子文档

registered_post_type

💡 云策文档标注

概述

registered_post_type 是一个 WordPress 动作钩子,在自定义文章类型注册后触发。它允许开发者在注册后执行自定义操作,常用于扩展或修改文章类型行为。

关键要点

  • 触发时机:在 register_post_type 函数成功注册文章类型后立即执行。
  • 参数:接受两个参数:$post_type(字符串,文章类型名称)和 $post_type_object(WP_Post_Type 对象,包含注册参数)。
  • 使用场景:适合在 init 钩子中调用,避免过早注册导致问题。
  • 功能支持:文章类型可支持多种核心功能,如元框、自定义字段、缩略图等,通过 $supports 参数配置。

注意事项

  • 确保在 init 钩子或之后注册文章类型,以避免初始化问题。
  • 从 WordPress 4.6.0 版本起,$post_type 参数改为接受 WP_Post_Type 对象,需注意兼容性。

📄 原文内容

Fires after a post type is registered.

Parameters

$post_typestring
Post type.
$post_type_objectWP_Post_Type
Arguments used to register the post type.

More Information

We can register a custom post type with the register_post_type function. This should not be hooked before init. So, the good option is to call it with an init hook.

Post types can support any number of built-in core features such as meta boxes, custom fields, post thumbnails, post statuses, comments, and more. See the $supports the argument for a complete list of supported features.

Source

do_action( 'registered_post_type', $post_type, $post_type_object );

Changelog

Version Description
4.6.0 Converted the $post_type parameter to accept a WP_Post_Type object.
3.3.0 Introduced.