有什么方法可以禁用在 WordPress (3.0) 中的自定义帖子类型下添加新帖子的选项吗?我研究了标签和参数,但找不到任何类似于此类功能的内容。
最佳答案
有一个元功能create_posts
,即 documented here WordPress 使用它在插入各种“添加新”按钮和链接之前进行检查。在自定义帖子类型声明中,添加 capability
(不要与 cap
混淆),然后将其设置为 false
,如下所示。
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
。如果没有它,您将无法再访问帖子的编辑页面。
关于WordPress:在自定义帖子类型上禁用 "Add New",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3235257/