• Hello everyone,

    Today I was working on a WordPress theme and I had to create a custom post type and archive page for the post but to meet the requirement I had to make sure that user of the theme have to able change permalink setting from wordpress permalink setting.but as I tried the whole day I cannot able to make sure to the custom post get the permalink of which user defined on wordpress permalink setting.I tried to add.rewrite rule to false and play around with different options also everytime flash the permalink.Even I switched to different version of wordpress and deactivating all plugin available.Now before I give up and start working on settings API to register new settings to let user change permalink for my custom post type I want to make sure that its not possible to use wordpress provided permalink setting to achieve the permalink customization.Is what I am thinking is right or its possible to achieve this functionality?

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

    (@bcworkz)

    Permalink settings are only applied to the post post_type. CPT links are defined when the CPT is registered (the rewrite slug). It cannot include permalink tags such as %year%, %category%, etc. If you desire full end user permalink functionality like we have for posts, you’ll need to custom code your own implementation. Or maybe there’s a plugin that provides this functionality for you? IDK.

    It is possible to alter CPT links via filter, so you could get the current post permalink setting from the options table (option_name “permalink_structure”) and alter your CPT links accordingly. Or add a setting somewhere so the CPT permalink can be defined separately from the one for posts. You must always work in a base element unique to your CPT in any link so requests can be distinguished from posts.

    You’ll also need a custom rewrite rule so this CPT permalink can be correctly parsed by WP.

    Thread Starter Kazi Mohammad Foysal

    (@kmfoysal06)

    Thank you very much. I started implementing the idea and its working as requirement

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘post permalink for custom post type’ is closed to new replies.