[wp-trac] [WordPress Trac] #55066: Inconsistency in post URL when parent and child category assigned to the post and permalink structure includes category

WordPress Trac noreply at wordpress.org
Thu Feb 3 19:41:05 UTC 2022


#55066: Inconsistency in post URL when parent and child category assigned to the
post and permalink structure includes category
--------------------------+-----------------------------
 Reporter:  5um17         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Permalinks    |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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
 <?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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55066>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list