How to use same slug and URL structure for 2 custom post types using add_rewrite_rule

I have registered 2 post types ‘book’ and ‘movie’. Now the requirement is that these two post types should have the same URL structure like ‘example.com/item/9999’ where 9999 is the id of custom post. Both post type will have the same slug item and then ID of the post.

https://wordpress.org/plugins/permalinks-customizer/ . This is the plugin that full fill my requirement and allow me to customize the permalink of both post types as `’example.com/item/9999′. But this plugin works fine on new posts and do not work great for the existing 15100 of the posts. And my client also requires to do this manually, with code without the plugin.

I think this can be done by the add_rewrite_rule(). But I don’t Know that exactly how. Can anyone guide me to achieve this please?

Read more here:: How to use same slug and URL structure for 2 custom post types using add_rewrite_rule

Leave a Reply

Your email address will not be published. Required fields are marked *