Skip to content

Unable to delete pattern category that contains zero patterns #84865

Open

Description

@andreawetzel

Description

A user reported that they had removed all the patterns from a category but it still appears when editing a pattern in the "Add category" UI and they could not find a way to delete the category that now has zero patterns associated with it.

This is perhaps related to #53287

Step-by-step reproduction instructions

  1. Add a new pattern and assign it to a category
  2. Save the pattern
  3. Observe that you can see the new pattern category in Appearance > Editor > Design > Patterns (At this stage, you could delete the new pattern via the three dot menu on the top right)
  4. Edit the pattern again and remove it from the new category
  5. You will no longer see the pattern category in the list and cannot delete the category via the UI so there is no way to delete
  6. If you interact with the Add Category search box while editing a pattern, you will still see the category with Zero patterns when you begin typing the category title

Screenshots, screen recording, code snippet

Pattern View without EMPTY category
Image

Pattern edit screen that still shows EMPTY category under Add category
Image

The delete option that is shown when you can interact with a category that contains one or more patterns.
Image

Environment info

  • WP 7.1 playground
  • Twenty Twenty Five theme
  • Mac / Chrome

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. Peerapatfc commented on Oct 16, 2026

    @Peerapatfc

    Thanks for the report. I looked at why this happens in current trunk (6b45881), by reading the code only. I have not reproduced it in a running Site Editor.

    Why the empty category can't be deleted

    The Delete action lives in the "Actions" menu on the category's own page, and an empty user category can't reach that page or that menu:

    1. usePatternCategories only keeps categories with a non-zero count ("Filter categories so we only have those containing patterns"), for theme-registered and user-created categories alike: use-pattern-categories.js#L73-L77
    2. CategoryItem renders nothing when count is falsy, so the item is not shown in the sidebar even though the server-side view_list includes empty user categories ('hide_empty' => false): category-item.jsx#L11 and view-config-api.php#L374
    3. PatternsActions looks the category up in the filtered list and only renders the Rename/Delete menu if it is found, so the menu doesn't appear even if you open the category URL directly: actions.jsx#L14-L22

    The "Add category" field in the pattern editor lists all terms of wp_pattern_category, which is why the empty category still shows up there.

    So a user-created category whose last pattern was removed ends up orphaned: it still exists as a term, but nothing in the UI can reach it to rename or delete it.

    Question on the intended UX

    Before anyone writes a fix, which direction would the team prefer?

    • A) Keep empty user-created categories in the Patterns sidebar (e.g. shown with a count of 0) so they can be opened and deleted, while still hiding empty theme/core-registered categories.
    • B) Keep hiding empty categories in the sidebar, but allow deleting a category from somewhere else (for example from the category selector when editing a pattern).
    • C) Remove a user category automatically when its last pattern is removed from it.

    A looks like the smallest change (the hook and CategoryItem need to treat user categories differently from registered ones), but I'm happy to follow whichever direction you prefer. I also noticed the sidebar was recently moved to the view config (#76823) and #82569 touches the same area, so I'd like to avoid conflicting with that work.

    I'm interested in working on this if the direction is agreed.

  2. yashjawale commented on Oct 16, 2026

    @yashjawale
    Contributor

    Thanks for reporting the issue!

    I was able to reproduce the described issue & judging from the categories getting hidden in Patterns panel. Ideally they should also not show up on Add Category input. So a fix might be needed.

    Peeking at #53287 & the Issues/PRs it links. Can't find any discussion on what the ideal flow should be for empty custom categories.

    But we can have two flows:

    1. Delete the category from db, that way it won't show up in Add category input (we'll also need to redirect user to All patterns category once the last pattern from selected category is deleted, as currently we stay there with a "No results" message from the dataview)
    2. Just remove the pattern entry & keep category as-is like current behavior but then we'll also have to show the empty ones on Patterns page with an option to manually delete the category (option already exists).
  3. added
    [Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions