• Hello,

    I’ve looked everywhere, and it seems to be an issue with WP. I am giving my posts a parent and a child (category and subcategory) to make things more organized, but for some reason, wordpress cannot do that to all posts.

    My permalinks structure is as follows: example.com/%category%/%postname%/

    Now according to WP it should show both the parent and the child in the URI (site.tld/parent/child/post), but it doesn’t. After a lot of research, it turns out the only way to force it to do that properly is to give the parent a greater ID number than the child, which seems like a primitive tempo fix as it only makes things worse. What if I keep adding subcategories to that parent? That means I will have to keep on tinkering with my database on a regular basis. Is it possible to give the parent an ID of 9000 without causing conflicts with WP category creating system?

    Many suggested that I only select the sub-category from the post edit page, but this is not solving the issue. In fact, it is making it more messy. I want both categories to be added and both of them to be in the permalinks, in an organized way.

    Sorry for the long post, but I’ve been looking everywhere for a solution.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Trust me, your post is not long ??

    You can get WP to recognize a parent/child/post structure by using add_rewrite_rule(), but then all permalinks need to follow the same structure or the rule will get confused about what’s what. Alternately, include static parts so the rule can always determine what comes next.
    example.com/top/parent-cat/sub/child-cat/post-slug/
    “top” and “sub” always precede the corresponding category and are part of the rule’s regexp.

    As long as the post slug terminates the permalink, you can arbitrarily place nearly any text in front without any ill effects. You can’t have numbers because WP will try to make a date out of it, but plain text usually is OK.
    example.com/any-text-you want/is-ignored-as-long/as-a-post-slug-terminates-the-permalink/this-is-the-actual-post-slug/

    You will also need to filter permalink output to match the format you choose to use.

    arend

    (@arenddeboer)

    Have you found a solution, other than the one provided by bcworkz? This behavior looks like a bug to me..

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to force both category and sub-category in permalinks?’ is closed to new replies.