Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#48068 new defect (bug)

Weird behavior when setting hierarchical to false on the built-in taxonomy category

Reported by: kwellmann's profile kwellmann Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2.3
Component: Taxonomy Keywords:
Focuses: Cc:

Description

When altering the taxonomy args of the built-in taxonomy category and setting hierarchical to false unexpected things started to happen - tested on a fresh install of WordPress.

<?php
add_filter('register_taxonomy_args', function($args, $taxonomy) {
    if ($taxonomy == 'category') {
        $args['hierarchical'] = false;
    }

    return $args;
}, 10, 2);

After adding the code above as a simple plugin and activating it:
When moving the default post 'Hello world!' into trash the category changes from 'Uncategorized' to '1'.
Restoring it changes the category again. This time to '2'. Looking at the edit-tags.php?taxonomy=category page there are now two additional terms ('1' and '2') which have been automatically created.

When creating a new post it gets the newly created term '1' assigned instead of 'Uncategorized'.

When creating a new term with the name 'Test' and assigning it to my newly created post another term is automatically created ('5') which seems to replace term '2' since it is gone.

The 'new' term names seem to be generated based on the ID from a previous term.

On a side note:
On the edit-tags.php?taxonomy=category page everything is now labeled with 'Tag' instead of 'Category'.

Change History (2)

#1 follow-up: @johnbillion
5 years ago

  • Keywords reporter-feedback added

What's your reason for switching categories to non-hierarchical?

#2 in reply to: ↑ 1 @kwellmann
5 years ago

  • Keywords reporter-feedback removed

Replying to johnbillion:

What's your reason for switching categories to non-hierarchical?

Because a category is part of the permalink structure and there shouldn't be any parent child relation in general.
So using this filter seemed to be the easiest option.

Note: See TracTickets for help on using tickets.