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 yearly/ monthly archive permalinks
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- How can I rewrite URLs to pass taxonomy and post type values to the query?
- Using Custom Fields in Custom Post Type URL
- Removing base slug from hierarchical custom post type
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Adding meta values to permalink
- WordPress custom taxonomy URL rewrite on spelling errors
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- Custom Posttype Inheritance (and url structure)
- Adding %author% in custom post type URL structure?
- Post slug changed using code doesn’t reflect on editor when post is published
- Defining a default page for custom post type
- Pass parameter to custom post type single while keeping clean url
- Reslug a Custom Post Type
- Many to Many Taxonomies or rewrite rules?
- remove post-name from title in custom post type
- Rewrite custom post & taxonomy to share same URL path
- how to use two permalinks for one custom post type
- Custom post type’s slug gets wrong when adding a custom meta box
- Adding a date archive to Custom Post Type
- Bulk 301 redirect for custom post type
- Custom Permalink Tag breaks Pagination
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom Post Type and Custom Taxonomy Permalinks
- Pagination problem
- Custom post type with slug for plural (archive) and for single
- Custom Post Type Post have a Child `Page` Post Type Post
- remove permalink “front part” for custom post type
- Query var removed after rewrite
- Change Permalink Structure for Tag.php template
- Custom post types archive redirect
- Remove post type slug of all post types from permalinks
- Add archive slug to default post post type
- Custom Post type and permalink settings
- Permalink for a custom post type isn’t working and I don’t know why
- Assign same parrent Page to pages AND custom post types
- Versioned Custom Post Type (Not the same as revisions)
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- Multiple (two) category postings on the same page.
- Custom taxonomy returns 404
- Pretty URLs and custom post types
- Specific routing for CPT
- Lost of query parameter when using permalink
- Slug for custom post type
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- After creating Custom post type by user delete old one
- Dynamic CPT permalink structure based on ACF field value
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- Custom Post Type and Taxonomy Rewrite Error
- custom posts permalinks url rewriting
- Url Rewriting a dynamic wordpress page with parameters
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- How can I write slugs / permalinks as: custom post type -> custom taxonomy and custom post type -> custom taxonomy (one CPT and many taxo)?
- Display CPT taxonomies as an archive page
- Redirect Custom Post Type from Child Taxonomies
- Custom Post Type duplicating slug for new posts
- WordPress page not showing up – replaced with last 10 posts?
- Custom post type rewrite and wp_pagenavi interfering with each other
- Generate slug and meta data if meta field is empty
- redirect old post type url to new structure url
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Ideal top-level slug methods
- How can you preserve URLs when moving posts to a custom post type?
- Custom Post Type Base URL
- Custom Post Type and single-posttype template
- Create page using same slug as custom post type
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- How to rewrite custom slugs that follow my rules
- What is the best way to relate different custom post types?
- Allow child pages with the same base as the CPT slug
- Custom Post Type slug has the same Redirection entry