The best way to do it is right before you display the options page. Right before your call to settings_fields
, add this:
if( isset( $_REQUEST['settings-updated'] ) )
flush_rewrite_rules();
Remove the flush_rewrite_rules from your other function and that should do the trick. Its worked for me.
Related Posts:
- Redeclare/Change Slug of a Plugin’s Custom Post Type
- 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
- Rewrite post type slug only for child theme
- How to target a specific custom post type post and its all children and grandchildren?
- 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
- How to rewrite url for any specific taxonomy?
- Programmatically rewriting slug through functions.php but returns 404
- Including taxonomy term before post type breaks top level pages
- Change Slug of a Custom Post Type
- WordPress Custom Post Type – Rewrite Query
- Custom Post Type Advanced Slug
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Custom Post Types and Removing Slugs – should we do it?
- Custom rewrite rule based on other custom post type title
- Custom Post Type not using correct page template
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Using get_post_type with a custom URL format?
- Two CPT: one is using part of the custom rewrite slug from the other
- WordPress page not showing up – replaced with last 10 posts?
- Custom permalink rewrite rules – how do I fix this?
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- Custom Post Type Rewrite Rule
- Generate daily archive whenever any post type is added
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Custom post type Premalinks main page and details page
- Is it possible to use a post name in a custom post slug?
- 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
- How to have custom post type /example/ and then posts /example/posts.html
- Remove url rewrites for registered taxonomies
- Add archive slug to default post post type
- Custom Post type and permalink settings
- Show category ID on custom post type
- How to customize a permalink (URL) structure?
- CPT custom archive template does not get loaded
- Am I using the flush_rewrite_rules function in the right place?
- Rewrite slug for CPT
- Custom Post Type with Templates using Meta Boxes?
- Rewrite slug of custom post type to include post-id
- Can I list a custom post type within another custom post type in the admin area?
- Is there a way to have custom post type and page with the same slug?
- Rewrite rules for custom posts types
- Using Same Slug With Multiple Post Types
- wp_list_categories() – current-cat class also inside posts?
- Custom Post Types, URL rewrite on multiple CPTs
- Can’t edit custom post type
- How can we take into account post types when constructing permalinks?
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Get Taxonomy Term Title by it’s URL
- Set URL link to featured image of custom post type
- Child post with numeric only slug keeps redirecting to parent
- Taxonomy custom post type URL
- How to change custom post type permalink structure
- How to add a post slug to a url?
- Change CPT archive title
- AJAX load more for different custom post type loops
- PHP variable not regenerating when publishing multiple posts at the same time
- Front custom edit post page for each post
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Categories of Custom Post throws gives 404
- On update or create post redirect to current post position in list
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- I need to add endpoint for wordpress categories
- How to build custom route by adding taxonomies to URL ? ex: www.demo.com/communities/palo-alto/
- Adding Post id to the end of slug in a Custom Post Type
- Remove the parent slug in a CPT URL
- Permalink for a custom post type isn’t working and I don’t know why
- 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?
- Featured image overlay when changing post status
- Rewrite Question Mark in Post Template to Make it Pretty URL
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- get_post_meta not working on publishing
- Redirect 404 page with ID in slug to associated page with same ID in slug
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Display featured image from one CPT within another CPT query
- Query taxonomy of taxonomy of custom post type
- Assign same parrent Page to pages AND custom post types
- Best way to style first post differently?
- WordPress custom post type permalink rewrite shows page not found
- Allow duplicate slugs for custom post type with taxonomies
- Using taxonomy term in CPT permalink – Pages 404’s
- Addition of custom option panel crashes Media Library & Admin Area
- How to make custom posts types display when published for the future
- Nested Custom Post Type or Custom Post Type Parents?
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Custom post type as home page with custom url