You need to either go into Settings -> Permalinks
and click Save
Or if you’re doing this programmatically you need to use flush_rewrite_rules()
, but make sure this is only used when you activate/deactivate the plugin, DON’T set this in code that runs (like in init, or on every page load):
https://developer.wordpress.org/reference/functions/flush_rewrite_rules/
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
register_activation_hook( __FILE__, 'wdocs_flush_rewrites' );
/**
* Flush rewrite rules on activation
*/
function wpdocs_flush_rewrites() {
// call your CPT registration function here (it should also be hooked into 'init')
wpdocs_custom_post_types_registration();
flush_rewrite_rules();
}
Related Posts:
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- How to modify URL structures in custom post types and taxonomies or terms
- Permalink rewrite with custom post type and custom taxonomy
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- Custom Permalink Tag breaks Pagination
- Custom Permalink for Taxonimie and Custom Post Type
- Permalink Structure CPT With Custom Taxonomy Fails
- Customize Custom Post Type URL
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Parent cpt/child custom post type URL permalink relationship
- Mixing custom post type and taxonomy rewrite structures?
- Rewriting a custom-post-type permalink with taxonomy term?
- Custom Post Type Permalink / Rewrite not working immediately
- Custom rewrite rules for archive page and single post
- Multiple post types – share same ReWrite slug?
- Permalink rewrite 404 conflict- WordPress Taxonomies/ CPT
- Adding meta values to permalink
- Archive page with multiple taxonomies rewrite
- Permalinks so that one custom post type appears to be a child of another, not working
- Create permalink structure for one taxonomy archive per custom post type
- Help with a TV series Rewrite structure
- Taxonomy archives based on Custom Post Type
- Custom permalinks
- Prepend meta_value to permalink of post
- How to check if last uri segment is a custom post type or taxonomy term?
- Custom Permalinks for Custom Post Types and Taxonomies
- Permalinks for CPT breaks permalinks to pages
- Including two taxonomies in a permalink structure
- How to rewrite custom post type URL for multiple depths instead of one specific depth
- Custom post type category, taxonomy and URL rewrite problem
- Permalink Structure problem with cpt and custom taxonomy
- WordPress Rewrite rule for nested post types
- how to get archive urls with same origin for custom types and terms?
- multiple url slug for single custom post type
- Add hierarchical taxonomy to permalink for custom post type
- Custom Post Type and Custom Taxonomy Permalinks
- Parent & Child Taxonomy slugs in custom post permalink
- Change Permalink Structure for Tag.php template
- Making a custom help center page
- Custom taxonomy in URL showing 404
- Remove url rewrites for registered taxonomies
- How to change custom post type permalink structure
- Adding custom post category slug in permalink causes 404 error for pages and posts
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Custom taxonomy rewrite with query var returns %2F in URL
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- CPT’s with landing page instead of archive – Url Rewrite?
- How to get list of taxonomy slugs ordered parents>childs?
- Pretty URLs and custom post types
- Custom permalink with child taxonomy terms
- Best way to specify “article type” in URL
- Combine multiple CPT names to create valid permalinks
- Set parent for custom post type archive rewrite url
- Route subpage to Custom Post Type
- Custom Post Type Advanced Slug
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- How to rewrite the post slug of a custom post type post
- Modifying rewrite rules to use /category//
- Custom taxonomy and post type rewrite rules
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Rewrite URL for CPT to domain/post-name/post-id
- How to properly set the rewrite rules for this case?
- Custom permalink structure for custom post types including multiple taxonomy
- Change CPT permalink to use the category
- How to fix 404 on post after prepending Custom Post Type url with Custom Taxonomy Term slug
- Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post
- Redirect Custom Post Type from Child Taxonomies
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Customise Permalink Structure For Custom Post Types
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- Two CPT: one is using part of the custom rewrite slug from the other
- Template hierarchy changes when custom post-type permalink leverages custom taxonomy
- Associate custom CPT with another CPT’s taxonomy and rewrite permalinks
- Custom Post Type rewrite url to /category/pagetitle [duplicate]
- WordPress custom post type rewrite rule matches all pages returning 404
- page not found for example.com/custom-post-name
- redirect old post type url to new structure url
- Why won’t this rewrite rule work?
- Adding rewrite rules to Custom Post-type mixed with Taxonomy
- Custom Taxonomy in Permalink from post type
- Custom post type permalink structure
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- Two Permalinks with one Taxonomy (custom taxonomy) and (custom post type -> custom taxonomy)
- What is the best way to relate different custom post types?
- Add parent/child taxonomy to custom post type url
- Custom post types and permalinks
- Add a permalink variable onto custom post type URL after post name slug
- Custom Taxonomy Archive generates 404