The problem is caused by flush_rewrite_rules()
. Remove that line and the issue should be resolved.
If you call that function on every page load it can cause issues like this with permalinks. This function should only be run once after your theme or plugin is activated (but not on the activation hook, since that’s too early). This is because permalinks are persistent and should only be flushed if something has changed.
It’s often easier to just manually flush the permalinks by visiting Settings > Permalinks.
Related Posts:
- Taxonomy page returns 404 page not found
- Prepend meta_value to permalink of post
- Removing CPT slug from URL results in 404 error for archive page
- Getting Post ID from slug during init
- Interesting Custom Post Type Slug with Taxonomy and Custom Field
- Rewrite rules for custom post type slug
- How to remove slugs from multiple custom post types
- Change custom post type slug from plugin options
- Rewrite post type slug only for child theme
- Custom rewrite url category
- Index page with the same id as the slug
- How can I make the slug of the taxonomy also the slug of the custom post
- Programmatically rewriting slug through functions.php but returns 404
- Including taxonomy term before post type breaks top level pages
- WordPress Custom Post Type – Rewrite Query
- Custom Post Type Advanced Slug
- Custom Post Types and Removing Slugs – should we do it?
- Custom rewrite rule based on other custom post type title
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Two CPT: one is using part of the custom rewrite slug from the other
- Custom Post Type Rewrite Rule
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Custom post type Premalinks main page and details page
- Custom slugs with dates & IDs on Custom Post Type
- Add post id to url instead of WordPress default -2 suffix
- Custom post type slug localization
- Custom post type’s permalink adds the name of the post type before the post name
- Taxonomy in URL
- Custom taxonomy and post type with same slug
- Custom permalink with child taxonomy terms
- Remove permalink for custom post type
- Custom post type archive with page as parent url
- Permalink misbehaving in Custom Post Types
- Auto Slug Generation for Custom Post type
- How to make a posttype show under a page hierarchy (example.com/page/posttype/entry)?
- Best way to specify “article type” in URL
- Custom Post Type archive-{post-type}.php not working
- Custom post type single page (single-{CPT-name}) 404 when slug includes hyphens
- How do you create %post_type%/%postname%/ permalink structure?
- Slug for custom post type
- Pagination custom post type not working with rewrite slug
- Rename a slug label
- Custom Rewrite Rule for Custom Post Type with URL Param
- Slug Confusion Between Post and Custom Post types?
- WordPress custom slug rewrite
- How to find a specific post_type using its “rewrite slug”?
- Different slug taxonomy for two different CPT
- Custom URLs in post types make it impossible to view archive
- How to add current custom taxonomy slug to body class
- Change Slug of a Custom Post Type
- Using page slug in wp_query
- I can’t access custom taxonomy page listing
- How to have permalink like domain.com/term/postname?
- How can Custom Post Type and a page have the same slug?
- How to get postname in custom page?
- Custom Permalinks for Custom Post Types
- Listing all slugs?
- Why WordPress is picking archive.php instead of page.php?
- post_type_link Filter – Too Few Arguments
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Changing slug of all posts
- Share root slug for Child Page and Custom Post Type (prioritizing child pages over posts)
- Combine multiple CPT names to create valid permalinks
- WordPress different templates for same type custom post (but different slug)
- After creating Custom post type by user delete old one
- Set parent for custom post type archive rewrite url
- Route subpage to Custom Post Type
- Custom Post Type Category URL
- Add term slug in URL of custom post type details page
- Programmatically add custom field to post_name in a custom post type
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- Dynamic CPT permalink structure based on ACF field value
- How do I know if a rewritten rule was applied?
- How to create custom search result page with custom URL parameters for custom post type?
- Automatically update slug with latest title within custom post type [duplicate]
- WordPress rewrite url
- Apply template by path/slug related to custom post type?
- Page inside custom post type (url rewrite?)
- URL Rewrite – Page Archive
- url rewriting for custom post types
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Post type Permalink
- Changing CPT slug and taxonomy already registered in parent theme
- Custom Post Type to replace Woocommerce products – page not found error
- How to constrain the results to a specific post_type on tag archive page?
- How Can I Remove Custom Post Type Slug From URL
- WordPress custom permalink and archive link for custom post type
- How to rewrite the post slug of a custom post type post
- get_post_permalink() and custom permalink rewriting
- Custom Post Type for Shortcode Use – Prevent it display as a post (with slug)
- rewriterule not working
- Urls in Custom Post Type work for Terms but not for its Taxonomies
- How to use a specific custom field in a custom post type as slug
- Custom post type URL
- Pagination for custom post types – url rewriting
- Modifying rewrite rules to use /category//
- Custom Post Type View Button in Admin Gives 400 Error
- Add Custom Values to Permalinks Through Custom Fields and Posts
- sort by name (slug) custom post type
- Taxonomy rewrite pagination 404