Add new custom post type screen (admin area) results into 404

I created a custom post type (inside a plugin) which is not accessible public, means no single page, search results, archive etc. It’s only being used for custom queries.

add_action( ‘init’, function() {

$labels = array(
‘name’ => _x( ‘Tables’, ‘Post Type General Name’, ‘my-textdomain’ ),
‘singular_name’ => _x( ‘Table’, ‘Post Type Singular Name’, ‘my-textdomain’ ),
‘menu_name’ => __( ‘Tables’, ‘my-textdomain’ ),
‘name_admin_bar’ => __( ‘Table’, ‘my-textdomain’ ),
‘archives’ => __( ‘Table Archives’, ‘my-textdomain’ ),
‘attributes’ => __( ‘Table Attributes’, ‘my-textdomain’ ),
‘parent_item_colon’ => __( ‘Parent Table:’, ‘my-textdomain’ ),
‘all_items’ => __( ‘All Tables’, ‘my-textdomain’ ),
‘add_new_item’ => __( ‘Add New Table’, ‘my-textdomain’ ),
‘add_new’ => __( ‘Add New’, ‘my-textdomain’ ),
‘new_item’ => __( ‘New Table’, ‘my-textdomain’ ),
‘edit_item’ => __( ‘Edit Table’, ‘my-textdomain’ ),
‘update_item’ => __( ‘Update Table’, ‘my-textdomain’ ),
‘view_item’ => __( ‘View Table’, ‘my-textdomain’ ),
‘view_items’ => __( ‘View Tables’, ‘my-textdomain’ ),
‘search_items’ => __( ‘Search Table’, ‘my-textdomain’ ),
‘not_found’ => __( ‘Not found’, ‘my-textdomain’ ),
‘not_found_in_trash’ => __( ‘Not found in Trash’, ‘my-textdomain’ ),
‘featured_image’ => __( ‘Featured Image’, ‘my-textdomain’ ),
‘set_featured_image’ => __( ‘Set featured image’, ‘my-textdomain’ ),
‘remove_featured_image’ => __( ‘Remove featured image’, ‘my-textdomain’ ),
‘use_featured_image’ => __( ‘Use as featured image’, ‘my-textdomain’ ),
‘insert_into_item’ => __( ‘Insert into table’, ‘my-textdomain’ ),
‘uploaded_to_this_item’ => __( ‘Uploaded to this table’, ‘my-textdomain’ )
);
$args = array(
‘label’ => __( ‘Table’, ‘my-textdomain’ ),
‘description’ => __( ‘Table Post Type’, ‘my-textdomain’ ),
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘editor’ ),
‘hierarchical’ => false,
‘public’ => false,
‘show_ui’ => true,
‘show_in_menu’ => false,
‘menu_position’ => 25,
‘show_in_admin_bar’ => false,
‘show_in_nav_menus’ => false,
‘can_export’ => true,
‘has_archive’ => false,
‘exclude_from_search’ => true,
‘publicly_queryable’ => false,
‘rewrite’ => false,
‘capability_type’ => ‘post’,
‘show_in_rest’ => false,
);
register_post_type( ‘my_table’, $args );

}, 0 );

When hitting the “Add new” button ( https://domain.com/wp-admin/post-new.php?post_type=my_table ) via admin area, it results into a 404 error on the frontend.

This only happens on one single installation, others work fine.

Already re-saved permalinks (which shouldn’t be related at all) and manually used flush rewrite rules function. The htaccess looks as follows:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Additionally I installed another plugin which uses CPT (here public accessible) and it works fine for it.

Deactivated all plugins and also switched back to WP’s default theme, didn’t help.

Really strange one.. Any idea what it could be?

Read more here:: Add new custom post type screen (admin area) results into 404

Leave a Reply

Your email address will not be published. Required fields are marked *