wordpress自定义文章类型public参数说明

wordpress创建自定义文章类型函数register_post_type的public参数有点难以搞明白,该参数在官网的说明中说:

public

(boolean) (optional) Whether a post type is intended to be used publicly either via the admin interface or by front-end users.

Default: false
  • 'false' - Post type is not intended to be used publicly and should generally be unavailable in wp-admin and on the front end unless explicitly planned for elsewhere.
  • 'true' - Post type is intended for public use. This includes on the front end and in wp-admin.

Note: While the default settings of exclude_from_search, publicly_queryable, show_ui, and show_in_nav_menus are inherited from public, each does not rely on this relationship and controls a very specific intention.

是否准备让文章类型在前台和后台管理界面公开。设置成flase的时候,文章类型将不会被公开使用,设置为true的时候,文章类型可以在前台和后台公开使用。

当你把public设置才fasle后,再到后台看,发现后台没什么变化,访问添加的该类型文章,也能显示,切换这个参数的值,没能发现什么变化,其实这个参数的说明中后面的Note是重点,这个参数的作用算是给另外几个参数继承用的,也就是设置了这个参数后,其它几个参数可以直接继承这个参数的值,不需另外设置。如果其它参数你都设置了具体的值,这个参数设置成ture或false都没什么关系了。

你也可以查看该register_post_type函数的源码,在wp-includes/post.php文件中,可以看到public参数只是在其它参数:exclude_from_search, publicly_queryable, show_ui, and show_in_nav_menus are inherited from public没有值的时候给它们个默认值。

已有0评论

暂时木有评论.

发表评论