I use the permalink structure /%post_id%/%postname% because I have user submitted content. The problem is that %postname% still auto-increments itself and looks funny, even though the post id makes it unique. Is there a way to disable %postname% auto-incrementing?
domain.com/634/apple-pie
domain.com/635/apple-pie-2
domain.com/636/apple-pie-3
should be:
domain.com/634/apple-pie
domain.com/635/apple-pie
domain.com/636/apple-pie
Bonus points if you can do this just for a specified custom post type.
Hi @Thompson:
Unfortunately the post name must be unique for a given post type, and hierarchy level if the post type is hierarchical.
There are a couple ways to address this:
Use
/%post_id%-%postname%/
instead of/%post_id%/%postname%/
; that makes it unique and thus won’t append any annoying-N
s to the end of your URLs and will give you a slight improvement in SEO since the important keywords will be in the website root and not one directory level down. OrIf you must have the URL structure you specify then you can just set your permalink to
/%post_id%/
and use the'post_link'
and'init'
hooks to allow you to respectively append the post name onto the URL and to add a permastruct that matches apost_id
, a slash, and anything after the slash but throws the latter two away because they are not used with the permalink structure:Try this: