WordPress:禁用“添加新"关于自定义帖子类型 [英] WordPress: Disable "Add New" on Custom Post Type

查看:34
本文介绍了WordPress:禁用“添加新"关于自定义帖子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以禁用在 WordPress (3.0) 的自定义帖子类型下添加新帖子的选项?我查看了标签和参数,但找不到任何与此类功能类似的内容.

Is there any way to disable the option of adding a new post under a Custom Post Type in WordPress (3.0)? I've looked into labels and arguments but can't find anything that would resemble such a feature.

推荐答案

有一个元能力 create_posts此处记录,WordPress 使用它在插入各种添加新"按钮和链接之前进行检查.在您的自定义帖子类型声明中,添加 capabilities(不要与 cap 混淆),然后将其设置为 false,如下所示.

There is a meta capability create_posts that is documented here and is used by WordPress to check before inserting the various 'Add New' buttons and links. In your custom post type declaration, add capabilities (not to be confused with cap) and then set it to false as below.

register_post_type( 'custom_post_type_name', array(
  'capability_type' => 'post',
  'capabilities' => array(
    'create_posts' => false, // Removes support for the "Add New" function ( use 'do_not_allow' instead of false for multisite set ups )
  ),
  'map_meta_cap' => true, // Set to `false`, if users are not allowed to edit/delete existing posts
));

您可能还想将 map_meta_cap 设置为 true.没有它,您将无法再访问帖子的编辑页面.

You'll probably want to set map_meta_cap to true as well. Without it, you won't be able to access the posts' editing pages anymore.

这篇关于WordPress:禁用“添加新"关于自定义帖子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆