• Hello WordPress Support Team,

    I am encountering an issue with permalinks in WordPress version 4.6.2. It seems that there is a conflict in handling permalinks for different post types, specifically between posts and pages.

    Steps to Reproduce:

    1. Create a new post in the ‘Posts’ section with the title “example”. The permalink automatically generated for this post is url/example.
    2. Create a new page with the same title “example”. The permalink for this page is also generated as url/example, identical to the post’s permalink.
    3. When I visit url/example on the frontend, the content displayed is from the page, not the post.

    Expected Behavior: I expected WordPress to either generate a unique permalink for the page or provide some indication of a conflict, considering there is already a post with the same permalink.

    Actual Behavior: WordPress does not seem to differentiate between the post and the page with identical permalinks. The page content is displayed for the url/example permalink, while the post with the same permalink is not accessible.

    Questions:

    • Is this behavior expected in WordPress 4.6.2?
    • If not, could you please guide me on how to resolve this issue?
    • This topic was modified 10 months, 2 weeks ago by vthwang.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I can replicate the behavior you describe in 6.4.2 with no plugins and 2021 theme. I’m sure this is a bug. The function wp_unique_post_slug() is supposed to append a numeric suffix(-1, -2, etc.) when a slug already exists.

    I recommend submitting a bug report to our Trac system. Until this can be corrected in core, your only recourse is to manually assign a unique slug to either post or page (Visible title can remain the same). That is, unless you have the coding skill to identify the root cause and come up with a patch. If you do, apply the patch to your installation and add the patch file to your bug report.

    Thanks for bringing this to our attention!

    Thread Starter vthwang

    (@vthwang)

    Thank you for your response. After conducting some research, I discovered that this behavior is indeed a deliberate design choice by the WordPress Core Team.

    The comment from the WordPress Team, found in wp-includes/post.php between lines 5096 and 5099, clarifies this:

    /*
    * Page slugs must be unique within their own trees. Pages are in a separate
    * namespace than posts so page slugs are allowed to overlap post slugs.
    */

    Additionally, the SQL query at line 5100 is designed to exclude conflicts in different post type names.

    Personally, I appreciate if WordPress includes the name conflict checking for different post types. However, I am curious about their decision for implementing it in this particular manner. Do you think it would be beneficial to bring this matter to the attention of the core team?

    Moderator bcworkz

    (@bcworkz)

    Pages are in a separate namespace than posts

    ??? I don’t think so, otherwise we’d be able request a post with the same slug as a page. It’s true for hierarchical child pages, but not for top level pages. Custom post types could also have the same slug because their permalink includes the post type, such as example.com/product/same-slug-as-page/. There’s no such distinction between top level page permalinks and post permalinks.

    Maybe something was different in the past? If you want to gain more clarity on the situation, you could post a Trac ticket anyway. Even if it eventually ends up with a “won’t fix” tag, you’ll likely gain more clarity on the topic from those that truly know all the nuances.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conflict in Permalinks for Different Post Types’ is closed to new replies.