0

Since Gutenberg I've used the plugin "Classic Editor" for one of my websites until I have time to make the necessary adjustments to fully work with the new Gutenberg look. I'm now starting to look at removing the plugin for the website and noticed an issue that I don't understand.

When editing a custom post type that I've created I no longer see the tags (called "type" in this case). I can see the categories fine, and the tag box appears but have no tags visible (even though I can see that the post has tags before I go in to edit the post).

List with posts showing tags

Inside the post, the box for tags are showing but no tags are visible

Does anyone know why this is happening? I've added 'show_in_rest' => true and tried making several different changes but nothing seems to work. This is my current code for adding the tag:

function create_topics_nonhierarchical_taxonomy() {
  $labels = array(
    'name'                          => _x( 'Type', 'taxonomy general name' ),
    'singular_name'                 => _x( 'Type', 'taxonomy singular name' ),
    'search_items'                  =>  __( 'Search Types' ),
    'popular_items'                 => __( 'Popular Types' ),
    'all_items'                     => __( 'All Types' ),
    'parent_item'                   => null,
    'parent_item_colon'             => null,
    'edit_item'                     => __( 'Edit Type' ), 
    'update_item'                   => __( 'Update Type' ),
    'add_new_item'                  => __( 'Add New Type' ),
    'new_item_name'                 => __( 'New Type Name' ),
    'separate_items_with_commas'    => __( 'Separate types with commas' ),
    'add_or_remove_items'           => __( 'Add or remove types' ),
    'choose_from_most_used'         => __( 'Choose from the most used types' ),
    'not_found'                     => __( 'No Types found.' ),
    'menu_name'                     => __( 'Types' ),
  ); 

  register_taxonomy('types','xx',array(
    'hierarchical'          => false,
    'labels'                => $labels,
    'show_ui'               => true,
    'show_admin_column'     => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var'             => true,
    'show_in_rest'        => true,
  ));
}
add_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );

Any help would be appreciated!

  • There's a Types panel and tag entry UI in the screenshot, it's under the permalink and above the other taxonomies – Tom J Nowell Mar 10 at 9:55
  • Yes, I mentioned this in my post. The problem is that I can't see the tags that have been entered, and if I try to add a new tag the ones available does not appear. – Amandau Mar 10 at 10:06
  • Where is this code located? And why do you override the update count callback? – Tom J Nowell Mar 10 at 13:04
  • This is located in the functions.php file. I wasn't sure what "update_count_callback" did, but I've tried removing it as well and it made no difference. I've gotten this code from some tutorial a long time ago! – Amandau Mar 10 at 13:43
  • Oooh, you should follow the official handbook and the official documentation for register_taxonomy instead at developer.wordpress.org, they're far better than most tutorials, and much more up to date. Also taxonomies, post types, etc, don't belong in themes. If your theme is lost or changed all that data dissapears! It's very anti-user/fragile, put it in a plugin instead – Tom J Nowell Mar 10 at 14:54
0

In this line

register_taxonomy('types','xx',array(

You should replace the xx with the custom post type name that you want the taxonomy to be applied.

| improve this answer | |
  • Yes of course, I've changed it to "xx" for censoring. Normally it's the name of the custom post type – Amandau Mar 10 at 11:01

Your Answer

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

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