0

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?

  • update your permalinks and after check once again. – Jignesh Patel Mar 19 '18 at 8:00
  • if you would read my question carefully you would know that I already did it and didn't help. – flowdee Mar 19 '18 at 8:09
  • args Array last item wrong comma – Pat_Morita Mar 19 '18 at 8:19
  • I've used your code as it is and it works perfectly here. – cybmeta Mar 19 '18 at 9:21
  • @Pat_Morita thanks for the tip but of course this is not related to an error ;) – flowdee Mar 20 '18 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.