0

Since Gutenberg 13.3 (and WP 6.1), a post term block variation is generated for each custom taxonomy registered. For example, if you register a “Product category” taxonomy, you should able to add a “Product categories” block that lists all the product category terms assigned to the current post.

I'm working on a plugin that registers a couple of custom taxonomies for a custom post type:

function register_post_types() {

    // Register custom post type (omitted for brevity)
    (...)

    // Register custom taxonomies
    $cat_labels = array(
        'name'          => __( 'Exhibit Categories' ),
        'singular_name' => __( 'Category' ),
        'add_new_item'  => __( 'Add New Category' ),
        'edit_item'     => __( 'Edit Category' ),
        'new_item_name' => __( 'New Category' ),
        'search_items'  => __( 'Search Categories' ),
        'all_items'     => __( 'All Categories' ),
        'popular_items' => __( 'Popular Categories' ),
    );
    $cat_args = array(
        'show_ui'            => true,
        'show_in_rest'       => true,
        'show_admin_column'  => true,
        'query_var'          => true,
        'public'             => true,
        'publicly_queryable' => true,
        'labels'             => $cat_labels,
        'hierarchical'       => true,
    );
    register_taxonomy( 'exhibit_category', 'exhibit', $cat_args );

    $tag_labels = array(
        'name'          => __( 'Exhibit Tags' ),
        'singular_name' => __( 'Tag' ),
        'add_new_item'  => __( 'Add New Tag' ),
        'edit_item'     => __( 'Edit Tag' ),
        'new_item_name' => __( 'New Tag' ),
        'search_items'  => __( 'Search Tags' ),
        'all_items'     => __( 'All Tags' ),
        'popular_items' => __( 'Popular Tags' ),
    );
    $tag_args = array(
        'show_ui'            => true,
        'show_in_rest'       => true,
        'show_admin_column'  => true,
        'query_var'          => true,
        'public'             => true,
        'publicly_queryable' => true,
        'labels'             => $tag_labels,
        'hierarchical'       => false,
    );
    register_taxonomy( 'exhibit_tag', 'exhibit', $tag_args );

}
add_action( 'init', 'register_post_types' );

Both the custom post type and the custom taxonomy are registered correctly as they appear in the admin side menu, but for some reason when searching for the generated post term block variations using the block inserter they don't show up.

In the following screenshot you can see the issue (Both the "Product tags" and "Product categories" taxonomies come from a WooCommerce install):

enter image description here

Any ideas?

6
  • Are you using the Gutenberg plugin? I'm not sure if these changes have been merged into WordPress core yet. Jun 30, 2023 at 7:59
  • This feature was added in WP 6.1: kinsta.com/blog/wordpress-6-1/…
    – leemon
    Jun 30, 2023 at 8:06
  • when does the registration code run? I can't see any functions wrapping it or hooks. I also can't get the same search results as your screenshot when testing, post tags don't show up at all, "taxo" only gives me a term description block in the search
    – Tom J Nowell
    Jun 30, 2023 at 8:08
  • 1
    Here's the code that's meant to register the variations: github.com/WordPress/gutenberg/blob/trunk/packages/…
    – Tom J Nowell
    Jun 30, 2023 at 8:11
  • The code runs in the "init" hook. I updated the posted code.
    – leemon
    Jun 30, 2023 at 8:13

1 Answer 1

0

Apparently, for the post term block variation automatic generation to work you need to register the custom taxonomies earlier in the process (a priority lower than 10).

Example: add_action( 'init', 'register_post_types', 9 );

I don't know if this is by design because it's not documented anywhere in the Gutenberg docs.

1
  • 1
    Just stumbled on this gotcha with register_taxonomy too. If you don't set priority below 10, querying the custom taxonomy does not work.
    – JDQ
    Jan 6 at 7:22

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.