Opened 3 years ago
Last modified 3 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: |
|
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.
Proposed solution