WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#45539 closed defect (bug) (worksforme)

Block Editor for CPT

Reported by: sovitranjitkar Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0
Component: Editor Keywords: needs-testing
Focuses: javascript, administration Cc:

Description

Hi there,

I have a CPT register with name register_post_type( 'themes', $args ); after updating to WP 5.0 I came to know that I have to add 'show_in_rest' => true to get the new block editor for CPT. I have added it and shows a new editor successfully. However, I cannot able to see the Featured Image section for both CPT's and core Post editor as well as registered Taxonomy section on CPT.

While debugging I found that there is an error on:

Failed to load resource: the server responded with a status of 400 (Bad Request)
http://localhost//wp/wp-json/wp/v2/themes?status=active&_locale=user:1


Uncaught (in promise) Error: [object Object]
at redux-routine.min.js?ver=3.0.3:1
at redux-routine.min.js?ver=3.0.3:1
http://localhost/wp/wp-includes/js/dist/redux-routine.min.js?ver=3.0.3

While changing the CPT name themes to any other name it shows Featured Image section in both CPT and core Post but not able to see registered Taxonomy sections on CPT.

Thank you!

Regards,
Sovit Ranjitkar
WordPress Developer/Designer

Change History (8)

#1 @swissspidy
2 years ago

  • Keywords reporter-feedback added; dev-feedback removed

Can you share the whole code you‘re using to register the post type?

#2 @sovitranjitkar
2 years ago

Hello @swissspidy Below are the code that I am using to register the post type if you found any mistakes you can also try registering a post type with your own way with post name themes seems like there is an issue with the name themes and you can easily see 2 errors while debugging with developer tools from the browser.
If you change the name to any other you can able to see the Feature Image section on both CPT and core Post but for the register_taxonomy on CPT there is no way to show it.

<?php
add_action( 'init', 'wptheme_store_themes_taxonomy');
/**
 * creates a custom taxonomy for custom post type themes post
 * @uses register_taxonomy
 * @uses init hook
 */
function wptheme_store_themes_taxonomy() {
        register_taxonomy(  
                'themes_categories', 'themes',                                  
                array(  
                        'hierarchical'  => true,  
                        'label'                 => 'Themes store',
                        'query_var'             => true,
                        'rewrite'               => array(
                                                                'slug' => 'themes/category',
                                                                'with_front' => false
                                                        )
                )
        );
}

/****************************************************************************************/
add_action( 'init', 'wptheme_store_register_custom_post_types' );
/**
 * Registering Custom Post Type Themes
 */
function wptheme_store_register_custom_post_types() {
        $labels = array(
                'name'                                  => _x( 'Themes', 'wptheme_store_custom_post','wptheme_store' ),
                'singular_name'                 => _x( 'Theme', 'wptheme_store_custom_post', 'wptheme_store' ),
                'add_new'                               => _x( 'Add New', 'wptheme_store_custom_post', 'wptheme_store' ),
                'add_new_item'                  => _x( 'Add New ThemePost', 'wptheme_store_custom_post', 'wptheme_store' ),
                'edit_item'                             => _x( 'Edit ThemePost', 'wptheme_store_custom_post', 'wptheme_store' ),
                'new_item'                              => _x( 'New ThemePost', 'wptheme_store_custom_post', 'wptheme_store' ),
                'view_item'                             => _x( 'View ThemePost', 'wptheme_store_custom_post', 'wptheme_store' ),
                'search_items'                  => _x( 'Search ThemePosts', 'wptheme_store_custom_post', 'wptheme_store' ),
                'not_found'                             => _x( 'No ThemePosts found', 'wptheme_store_custom_post', 'wptheme_store' ),
                'not_found_in_trash'    => _x( 'No ThemePosts found in Trash', 'wptheme_store_custom_post', 'wptheme_store' ),
                'parent_item_colon'             => _x( 'Parent ThemePost:', 'wptheme_store_custom_post', 'wptheme_store' ),
                'menu_name'                             => _x( 'Themes Posts', 'wptheme_store_custom_post', 'wptheme_store' )
        );      
        $args = array(
                'labels'                                => $labels,
                'hierarchical'                  => false,
                'description'                   => 'Custom Theme Posts',
                'supports'                              => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields' ),
                'taxonomies'                    => array( 'post_tag','themes_categories'),
                'show_ui'                               => true,
                'show_in_menu'                  => true,
                'menu_position'                 => 5,
                'show_in_nav_menus'             => true,
                'publicly_queryable'    => true,
                'exclude_from_search'   => false,
                'query_var'                             => true,
                'can_export'                    => true,
                'rewrite'                               => array('slug' => 'themes','with_front' => FALSE),
                'public'                                => true,
                'has_archive'                   => 'themes',
                'capability_type'               => 'post',
                'show_in_rest'                  => true
        );

        register_post_type( 'themes', $args );
}

#3 @TimothyBlynJacobs
2 years ago

This seems expected giving there is a /themes endpoint now. You can try modifying the rest_base arg to something other than themes when registering your post type.

#4 @swissspidy
2 years ago

You need to set show_in_rest for the custom taxonomy as well for it to show up.

#5 @sovitranjitkar
2 years ago

Thank you @swissspidy and @TimothyBlynJacobs for your solutions.

Seems like by default rest_base is set to post type key which is themes and I modify arg and added it like rest_base => my_custom_post and YES it worked fine and shows Feature Image sections in both CPT and core Post.
As far as I know rest_base is a Rest API but also I just want to know after modifying rest_base arg to something other than themes does this affect my related posts in anyway or not?

Thank you!

#6 @swissspidy
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I don‘t see why these should be affected. Modifying rest_base is a totally fine thing to do.

Closing this ticket now because the issue was resolved.

#7 @sovitranjitkar
2 years ago

Anyways, Thank you @TimothyBlynJacobs and @swissspidy for your time and support.

Have a great time. :)

#8 @SergeyBiryukov
2 years ago

  • Keywords reporter-feedback removed
Note: See TracTickets for help on using tickets.