Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55066 new defect (bug)

Inconsistency in post URL when parent and child category assigned to the post and permalink structure includes category

Reported by: 5um17's profile 5um17 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Permalinks Keywords: has-patch
Focuses: Cc:

Description

This is the same issue fixed in WooCommerce https://github.com/woocommerce/woocommerce/pull/21299

Generally, we create parent category first and then child category. In this case, If we assign both the categories to the post then the URL will look like http://example.com/parent-category/post-name

Now if we create child category first and then the parent category and assign both the categories to the post then the URL will look like http://example.com/parent-category/child-category/post-name (Note the both categories in URL)

Reason for this we are sorting the categories by IDs in ascending order. In https://core.trac.wordpress.org/browser/tags/5.9/src/wp-includes/link-template.php?rev=52642#L228

<?php
$cats = wp_list_sort(
        $cats,
        array(
                'term_id' => 'ASC',
        )
);

So the category created first is used to construct the URL.
This is causing issue with WPML. The translation of post have different URL structure due to the category IDs.

Test Steps

  • Set the permalink structure to /%category%/%postname%/
  • Create a parent category then a child category and assign to a post.
  • Create another category e.g. Child2 and then a new category e.g. Parent2, Edit Child2 and choose Parent2 as parent category.
  • Create another post and assign Child2 and Parent2 to the post.
  • Compare the URLs of both post. Those are different due to category IDs.

Attachments (1)

55066.diff (366 bytes) - added by 5um17 2 years ago.
Proposed solution

Download all attachments as: .zip

Change History (2)

@5um17
2 years ago

Proposed solution

#1 @NomNom99
2 years ago

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.