WordPress: Disable “Add New” on Custom Post Type


WordPress: Disable “Add New” on Custom Post Type



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.


Check if oe specific user is online

1:

Limit to the amount of posts on Word Press

Full credit to Seamus Leahy

There is a meta capability create_posts this is not documented although is used by WordPress to check before inserting the various 'Add New' although tons and links. WordPress: is_category function for custom taxonomy's termsIn your custom post type declaration, add capabilities (not to be confused with cap) and then set it to false as below.. how to customize wordpress internal functions, like adjacent_post_link()
register_post_type( 'custom_post_type_name', array(   'capability_type' => 'post',   'capabilities' => array(     'create_posts' => 'do_not_allow', // false < WP 4.5, credit @Ewout   ),   'map_meta_cap' => true, // Set to `false`, if users are not allowed to edit/delete existing posts )); 
May I ask why you want to did this?. how display more lines in wordpress-the_excerpt() I would at first have suggested changing the capabilities for your custom post type, although I don't think there's one this limits who must add posts, although only who must edit or publish them.. Export WordPress Nav Menus It looks a little dirty, although you could try unsetting the item in the $submenu global;. Dynamic shortcodes and functions in WordPress . How can I filter child categories of “uncategorized” out of the loop?
function hide_add_new_custom_type() {     global $submenu;     // replace my_type with the name of your post type     unset($submenu['edit.php?post_type=my_type'][10]); } add_action('admin_menu', 'hide_add_new_custom_type'); 
.

2:

There is a meta capability create_posts this is not documented although is used by WordPress to check before inserting the various 'Add New' although tons 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 )); 

3:

The combinations of the solutions above job in hiding the links (although any one could quite easily type the URL in directly.. The quick fix mentioned @PavelChernov relies on receive _post_type() which will only job if there is already a post in the listing. If there are no posts, the function will not return anything, and the "Add New" link will be available. An alternative method:.
function disable_new_posts() {     // Hide sidebar link     global $submenu;     unset($submenu['edit.php?post_type=CUSTOM_POST_TYPE'][10]);      // Hide link on listing page     if (isset($_GET['post_type']) && $_GET['post_type'] == 'CUSTOM_POST_TYPE') {         echo '<style type="text/css">         #favorite-actions, .add-new-h2, .tablenav { display:none; }         </style>';     } } add_action('admin_menu', 'disable_new_posts'); 
EDIT: To prevent direct access if any one types the URL in themselves: http://wordpress.stackexchange.com/a/58292/6003.

4:

add_action("load-post-new.php", 'block_post');  function block_post() {     if($_GET["post_type"] == "custom_type")          wp_redirect("edit.php?post_type=custom_type"); } 

5:

In wordpress and for all the post types there is the capability create_posts. This capability is used in several core files :.
  1. wp-admin\edit-form-advanced.php
  2. wp-admin\edit.php
  3. wp-admin\includes\post.php
  4. wp-admin\menu.php
  5. wp-admin\post-new.php
  6. wp-admin\press-this.php
  7. wp-includes\admin-bar.php
  8. wp-includes\class-wp-xmlrpc-server.php
  9. wp-includes\post.php
So if you really want to disable this feautere you need did it per role and per post type. I use the great plugin "User Role Editor" to manage the capabilities per role.. But what around the capability create_posts? Well this capability is not mapped and also create_posts is equal to create_posts so i should fix this and map the capability per post type.. So you must add this piece of code in your functions.php and the you must manage this capability. .
function fix_capability_create(){     $post_types = receive _post_types( array(),'objects' );     foreach ( $post_types as $post_type ) {         $cap = "create_".$post_type->name;         $post_type->cap->create_posts = $cap;         map_meta_cap( $cap, 1);      } } add_action( 'init', 'fix_capability_create',100); 
So here i are not hiding or removing menu elements... here i are removing the capability for users (including xmlrpc requests).. The action was init and not admin_init or anything else for the reason this init at priority 100 prevents the display of "add new" on admin bar, sidebar, etc (in all the wp interface)..

6:

WordPress Networks: I found this Seamus Leahy's answer doesn't job if you are logged in as a super admin of the network, it doesn't matter if the user doesn't have the capability, mapped or otherwise, when current_user_can($cap) is called by the CMS. By digging into the core I found you must did the following..
register_post_type( 'custom_post_type_name', array(   'capability_type' => 'post',   'capabilities' => array(     'create_posts' => 'do_not_allow', // Removes support for the "Add New" function, including Super Admin's   ),   'map_meta_cap' => true, // Set to false, if users are not allowed to edit/delete existing posts )); 
The accepted answer hides the menu item, although the page is still accessible..

7:

@ Staffan Estberg,. This is best way to hide the Add New or Create New although ton in custom postypes.
'capability_type'    => 'post',          'capabilities'       => array( 'create_posts' => false ),                 'map_meta_cap'       => true, 
It disable to create new post in custom post types both side in admin menu and above the list of post type..

8:

I found this simplest way for this. Just ad this code into theme’s function.php..
function hd_add_although tons() {     global $pagenow;     if (is_admin()) {         if ($_GET['post_type'] == 'custom_post_type_name') {             echo '<style>.add-new-h2{display: none !important;}</style>';         }     } } add_action('admin_head', 'hd_add_although tons'); 


89 out of 100 based on 64 user ratings 719 reviews

@