• Resolved user10522three

    (@zorrohere)


    At the moment I am using custom post type with archives. The url to monthly archives is example.com/2017/8/?post-type=type-slug

    Is it possible to change the url structure to example.com/type-slug/2017/8/

    I tried few configurations but nothing helped and couldn’t find anything related to customizing urls for CPT archives.

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

    (@bcworkz)

    When the post type is registered, the arguments “rewrite” and “public” should both be true in order to get a permastruct like you are looking for. You may need to visit the permalinks settings page (no need to change anything) in order to get WP to flush and regenerate the rewrite rules. There shouldn’t be any need to do anything else but those two things.

    Thread Starter user10522three

    (@zorrohere)

    Thanks for your response. I will test it and mark the question as resolved.

    One weird thing about this question, there is one tag added to the question which I didn’t add as it makes no sense to me. Did you add ‘FreelancerBCM’ tag to the question? Weird.

    Moderator bcworkz

    (@bcworkz)

    The tag was placed by a spammer, we removed the spam post that accompanied it, but failed to notice the added tag. It’s gone now ?? Thanks for pointing it out.

    Thread Starter user10522three

    (@zorrohere)

    Hi again,

    Can you please clarify a confusion? I would like to rephrase my question. Right now all my links to custom post type monthly archives are example.com/2017/8?post_type=type-slug. What I wish to do is get the monthly links as example.com/type-slug/2017/8. So instead of post_type being part of url query it should be part of url, is that possible? At the moment I am using toolset types plugin to create CPTs.

    I tried to get support from them but they said it is impossible to change it and that’s how wordpress writes urls. Can you please clarify?

    Thanks.

    Moderator bcworkz

    (@bcworkz)

    Well, as they’ve implemented their plugin, perhaps that is true, but as I stated, by registering a post type differently, you get a permalink like you want. Apparently with that plugin such a registration is not possible. If you were to register your own post types instead of using the plugin, you’ll find that is the case. Such custom code isn’t too complex in itself, but deciding on the right parameters can be confusing. Going with the defaults often suffices though.

    Another possibility is creating your own rewrite rules. Depending on how many post types you have, the rule may end up being rather complex. There’s no reason you couldn’t add several rewrite rules if that somehow made more sense. The crux of custom rewrite rules is arriving at the proper regexp that matches your permalinks, without erroneously matching other permalinks that need to be handled elsewhere.

    The other side of the custom permalink equation is getting WP to generate permalinks in the proper form. The solution is theme dependent, but most themes use the default WP functions. In that case, use “post_type_link” filter to cause the generated permalinks to be the format you want.

    When you change anything related to permalinks, you need to flush the rewrite rules to get the new permalinks to be recognized. For your own custom code, using flush_rewrite_rules() isn’t necessary, it’s a very resource intensive operation that doesn’t need to be repeated until another change occurs. I recommend instead manually triggering a flush by visiting the permalink settings page. This happens automatically once you leave the page. It’s irrational, but I feel better clicking the save changes button even though nothing was changed. I still haven’t gotten used to things updating automatically without needing to explicitly save ??

    Thread Starter user10522three

    (@zorrohere)

    I will go through it. Thanks. I don’t know how you manage to be so active on this forum, I tried but couldn’t continue but I plan to be active again soon.

    Moderator bcworkz

    (@bcworkz)

    I’m active because I let other things I’m supposed to be doing lapse. An addiction of sorts, I love coding and solving puzzles. At least it’s an addiction that helps others ?? It was easier when there were few questions that I could answer. By answering I learned more and could answer more questions, so the more I learned. I got sucked in!

    I recall your replies being very helpful, thanks for helping out. Anything you can contribute is greatly appreciated, but it’s important to not over extend yourself. Too bad I can’t follow my own advice.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Rewriting wordpress archive url of custom post type’ is closed to new replies.