• I don’t know if this has always been an issue on my site but I am encountering the following currently. I can’t create two pages with the same slug but different parent categories. Permalinks are set to /category/slug/

    For example, I have already published diygearreviews.com/impact-drivers/weight-test-results/ and now can’t create diygearreviews.com/drills/weight-test-results/

    When attempting to create the same slug under /drills/ WP auto saves it as /drills/weight-test-results-2/.

    WP then also redirects all traffic from /impact-drivers/weight-test-results/ to /drills/weight-test-results/, which isn’t intended.

    Is there any way to fix this so that I can use the same slug in different categories and serve the appropriate pages to users?

    • This topic was modified 2 years, 8 months ago by itsnathanham.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The short answer should be no, but there might be a way, untested though. You can override the unique slug name requirement through the ‘wp_unique_post_slug’ filter hook. But as you’ve seen, this can mean the wrong post could be returned in a query. I think a way to prevent this is to fix up the query vars in “pre_get_posts” action. If the requested page_name includes a parent slug, get that parent’s ID and set the “post_parent” query var with it. Remove the parent slug portion of the “page_name” query var. Then let the query run.

    Needing to make a query for the parent ID will effect performance a little. There could be other reasons a duplicate slug is normally not allowed, so this suggested scheme may not work as well as I think it will.

Viewing 1 replies (of 1 total)

The topic ‘Child-Parent Slug Issues’ is closed to new replies.