Skip to content

Templates for posts with the same title never get the slug suffix appended - #13278

Open
ntsekouras wants to merge 1 commit into
WordPress:trunkfrom
ntsekouras:fix-65966
Open

Templates for posts with the same title never get the slug suffix appended#13278
ntsekouras wants to merge 1 commit into
WordPress:trunkfrom
ntsekouras:fix-65966

Conversation

@ntsekouras

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/65966

When a template is created for a specific post or page, _wp_build_title_and_description_for_single_post_type_block_template() is supposed to append the post slug to the computed template title when more posts share the same title, so they can be distinguished in the templates list.

That check can never match though. The second query only sets title and is merged into $default_args, which contains posts_per_page => 1, so count( $posts_with_same_title_query->posts ) > 1 is always false. This has been the case since the function was introduced in 6.1(WordPress/gutenberg#43862).

Steps to reproduce:

Create two published posts with the same title.
In the Site Editor, create a template for each of them (Templates > Add template > Single item: Post).
Both templates show the same title (Post: {title}), without the (slug) suffix.
The fix is to let the second query fetch up to two posts, same as the taxonomy variant already does with number => 2 in _wp_build_title_and_description_for_taxonomy_block_template():

$args = array(
      'title'          => $post_title,
      'posts_per_page' => 2,
);

The taxonomy and author variants are not affected.

Screenshots

Screenshot 2026-08-26 at 1 26 34 PM

Use of AI Tools

Generated with Fable 5 and adjusted/reviewed manually.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@ntsekouras ntsekouras self-assigned this Aug 26, 2026
@ntsekouras ntsekouras added the bug label Aug 26, 2026
@ntsekouras ntsekouras changed the title Same title check in _wp_build_title_and_description_for_single_post_type_block_template can never match Templates for posts with the same title never get the slug suffix appended Aug 26, 2026
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant