Skip to content

Content Type: Handle duplicate slug generation for CPT's and Taxonomies #78341

Open
im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/generate-slugs
Open

Content Type: Handle duplicate slug generation for CPT's and Taxonomies #78341
im3dabasia wants to merge 2 commits into
WordPress:trunkfrom
im3dabasia:feat/generate-slugs

Conversation

@im3dabasia
Copy link
Copy Markdown
Contributor

@im3dabasia im3dabasia commented May 15, 2026

What?

Follow up to #77600

When duplicating a post type or taxonomy, we should ensure the generated slug is not taken.

Check https://github.com/WordPress/gutenberg/pull/77938#discussion_r3188159387on auto-fill

Ensures the generated slug when duplicating a post type or taxonomy is not already taken.

Why?

buildCopySlug incremented the trailing number once without checking availability, so duplicating the same item twice pre-filled the same slug both times.

How?

buildCopySlug now loops, incrementing the trailing number, until finding a free candidate. Each modal builds a takenSlugs set from both active registered types and draft records (since duplicates are stored as drafts).

Testing Instructions

  1. Enable the Content Types experiment (Gutenberg → Experiments).
  2. Go to Settings → Post Types (or Taxonomies).
  3. Duplicate a post type, confirm slug pre-fills as test2.
  4. Duplicate it again, confirm slug is now test3, not test2.

Testing Instructions for Keyboard

Tab to a row's actions menu → Duplicate → confirm slug field is pre-filled with a free slug → submit with Enter.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia changed the title Feat/generate slugs Content Type: Handle duplicate slug generation for CPT's and Taxonomies May 15, 2026
@im3dabasia im3dabasia requested review from ntsekouras and tyxla May 15, 2026 12:03
@im3dabasia im3dabasia self-assigned this May 15, 2026
@im3dabasia im3dabasia added [Type] Bug An existing feature does not function as intended Content types (experimental) Affects the content types experiment labels May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content types (experimental) Affects the content types experiment [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant