1

I have been trying to find a way to do it but I can't get it to work. I have tried show_in_rest => 'true' which works for custom post types but not custom taxonomies. I also found an example on here to add this to my functions file but it didn't work either.

function ux_portfolio_block_cat_editor( $args, $taxonomy ) {
    if ( 'my_taxonomy_name_here' === $taxonomy ) {
        $args['show_in_rest'] = true;
    }
    return $args;
}
add_filter( 'register_taxonomy_args', 'ux_portfolio_block_cat_editor', 20, 2 );
4
  • If you mean to have the editor on the taxonomy/term edit pages, then no, I don't think it's possible. But the editor uses the REST API, hence for the editor to be able to read/write/delete post data, post types need to be enabled in the REST API, so that's why 'show_in_rest' => true is needed for post types with the block editor support.
    – Sally CJ
    Commented Jan 19, 2021 at 1:12
  • Yeah, that's exactly what I meant. Wanting to have the editor on the taxonomy/category edit pages instead of the classic editor. Commented Jan 19, 2021 at 9:59
  • Then I guess you'll have to stick to the classic editor for now..
    – Sally CJ
    Commented Jan 20, 2021 at 5:42
  • 1
    Pity. Thank you for the answer though. Commented Jan 20, 2021 at 9:24

1 Answer 1

1

Yes you can. But you actually have to create your custom taxonomy in a slightly different way. Try this:

add_action('init', function () {
    $args = array(
        'show_in_rest'      => true,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => [ 'slug' => 'my_taxonomy_name_here' ],
    );
    register_taxonomy( 'my_taxonomy_name_here', [ 'post' ], $args );

    
    // Optional - create the custom post type
    $args = array(
        'description'       => 'YOUR_CUSTOM_POST_TYPE',
        'public'            => true,
        'menu_position'     => 5,
        'taxonomies' => array('my_taxonomy_name_here'),
        'show_in_rest'      => true,
        'supports'          => array( 'title', 'editor', 'thumbnail', 'taxonomies' ),
        'has_archive'       => true,
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => true,
        'query_var'         => true,
    );
    register_post_type('YOUR_CUSTOM_POST_TYPE', $args);
});

This will create custom post type, using Gutenberg, and even include your custom taxonomies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.