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
- How come Featured Image isn’t showing up in my Custom Post Type?
- Mixing custom post type and taxonomy rewrite structures?
- How to use a custom post type archive as front page?
- How to rewrite URI of custom post type?
- Set posts of a custom post type to be private by default?
- Custom post types – Use post_id in permalink structure
- Custom post type permalink: only use %post_id% and remove %postname%
- clients list using wordpress
- How can I add dropdown widget/box to admin post page?
- How to have a custom URL structure for a custom post type?
- Rewrite CPT slug with two taxonomy slug instead of one
- Custom Post Type slug same as page name causing a conflict
- Display only custom post type count for current author on the “At a Glance” dashboard widget
- Adding paged query to custom URL rewrite
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Rewrite Custom Post Type URL slug
- Custom Taxonomy breaking pages permalinks
- Customising rewrite rules for CPT single post URL to work as paged URL
- Custom WP TItle from custom template with dynamic URL structure
- GravityForm: Populate Dropdown with custom post type [closed]
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Change URL of posts and also Custom Post Type
- Custom post type and taxonomy slug issue
- WooCommerce product search titles only
- custom post type not showing in menu
- Remove url rewrites for registered taxonomies
- CPT custom archive template does not get loaded
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Query taxonomy of taxonomy of custom post type
- Create a custom php page and load it at a specific slug
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Rewrite custom post type url – Multiple post types
- Rewrites/query for multiple hierarchical custom post types
- Global custom meta box
- Auto Slug Generation for Custom Post type
- PHP question: how to combine syntax?
- Custom URLs in post types make it impossible to view archive
- How can Custom Post Type and a page have the same slug?
- Custom Permalinks for Custom Post Types
- WordPress different templates for same type custom post (but different slug)
- Route subpage to Custom Post Type
- Get current user id
- Pagination for custom post types – url rewriting
- Custom posts – tag pagination
- Custom meta box in custom post type not working
- Submit Custom Postypes from frontend
- Adding /blog in front of single posts (only)
- multiple URLS for the same page
- How to add specific terms in a custom post type?
- Define multiple prefixes for custom post type
- Limit custom post type to the authors only on front-end!
- Custom Post Type parent/child relationship rewrite rules for permalinks
- add .html to custom post type with WPML
- page not found for example.com/custom-post-name
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Force WordPress to only match URL in category
- Custom post type with parent page? Possible?
- Why won’t this rewrite rule work?
- Cannot modify a registered custom post type rewrite slug
- Allow authors to create article image
- Custom post type permalink structure
- How can i change url structure of cpt like this?
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs