I recently asked this question Custom post types – Use post_id in permalink structure and solved it but as I have enabled 'has_archive' => true
the solution given no longer works. Let me explain:
I’m after this structure:
archive-events.php
=> /news/events/single-events.php
=> /news/events/%post_id%/%postname%
To get post_id
in a single event permalink I’ve had to add %post_id%
to the CPT slug but when enabling has_archive => true
the archive page becomes the slug; in this case becoming /news/events/%post_id%/
which is invalid.
So my question:
How do I have post_id in permalink structure when using has_archive => true
To get what you need you have to add a custom rewrite rule and to filter the permalink construction. The following code does both:
Visit
wp-admin/options-permalink.php
one time to let WordPress update its rewrite rules.