我有个问题this 文档
为什么我要像文档建议的那样在init函数中注册自定义Post类型?这是不是只有在我没有使用插件的情况下才会出现?
据我所知,init runs every-time WordPress runs/is-loaded 由用户提供。这难道不意味着网站在每次访问时都会不必要地重新注册新的帖子类型吗?为什么不(如果构建插件)在require_once plugin_dir_path( __FILE__ )
当插件激活时?
这难道不会加快网站的速度吗?还是我在口译init()
错误的当然,自定义的post类型存在于数据库中的某个位置,因此不必在每个init()
?
下面是文档中的自定义帖子类型示例,使用init()
:
function create_post_type() {
register_post_type( \'acme_product\',
array(
\'labels\' => array(
\'name\' => __( \'Products\' ),
\'singular_name\' => __( \'Product\' )
),
\'public\' => true,
\'has_archive\' => true,
)
);
}
add_action( \'init\', \'create_post_type\' );