You simply need to visit the Settings > Permalink page (you don’t have to do anything there) after saving the settings.
If I had written the saving function myself, I could just call flush_rewrite_rules()
Not quite. flush_rewrite_rules()
would have to be called after the custom post type is ‘updated’ to reflect the changes, that is, after you register it. So you would need to call it on the next page load, after the CPT is registered.
You could use a transient to trigger flush_rewrite_rules() on the next (and only the next) init
(and after CPT is registered). To be clear, flush_rewrite_rules()
is expensive and shouldn’t be called regularly, this is why I suggest simply telling your plug-in users to visit the Settings > Permalink page after altering any permalink options – that way the rules get flushed only when its really needed.
Related Posts:
- Trigger custom action when setting button pressed
- How to hook update_post_meta and delete_post_meta?
- Are there any hooks that alter the 404 logic?
- WooCommerce: change display order of product short description and price [closed]
- Hooks for trashing, deleting, saving, restoring custom post type
- Is there a WordPress core & plugins update action hook?
- trigger save_post event programmatically
- Implementing advanced add_* function wrappers
- Hook into wp_head(); in a plugin
- is it possible to get the hook name in add_action?
- Use $query->set multiple times with pre_get_posts?
- How can I hook into the post editor title field in order to change the HTML?
- deactivated_plugin hook: get the name of the plugin
- WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”
- Can’t get ID of post that relates to the comment
- Searching hook to set cookies before and avoid “headers already sent”
- Hook before inserting user into database [duplicate]
- WP Admin Bar frontend issue with dashicon deregister
- wp_redirect() not working on form submission with init hook
- add_action for lost_password or modify wp-login.php?action=lostpassword
- Add my own function to existing WooCommerce hook
- Firing a function AFTER redirect
- WooCommerce – Overwrite action hook [closed]
- Admin Hook at the Login Page
- Which Hook? Hide attachments from specific post types in media library
- Why is save_post hook being called twice despite all my efforts?
- Custom action on login and “remember me”
- What’s hook to use immediately after a user is authentcated [duplicate]
- Hook before posting via JSON REST API
- add_action for unknown custom post types
- How to hook into Add New Member in BuddyPress
- Using wp_editor tinyMCE in metabox cause form alert on leaving page
- TinyMCE as comment editor – encoding issues
- Method to find a hook
- Understanding WP
- Hook when new CPT published AND postmeta inserted
- Need to check is_archive during init
- When WP_CLI runs WordPress from the command line, are hooks called?
- Executing Arbitrary Code at a Specific URL without Creating a Post or Page?
- Query categories that have a description
- customize_controls_enqueue_scripts doesn’t fire from within my plugin
- Save User Meta Email Address in Lowercase
- Trying to run a compile command while saving post
- How to cancel the trash action inside wp_trash_post
- wp_insert_post_data hook should be called before updating db but isn’t
- Action hook for custom tax edit
- wp cron job fires at every second or so, if callback is wrapped with DOING_CRON check it never fires at all
- load-* hook for dashboard
- I don’t understand how add_action and do_action work in tandem. The former executes the code already…what is do_action for?
- Insert HTML in post, below nav bar but above content?
- Convert Gravity Form Entry Date on Export
- Hook Adding content after title
- Fatal error: Call to a member function get_queried_object_id()
- Use an array of page template slugs and $hook
- “admin_enqueue_scripts” hook or $_GET[‘page’]?
- How to add content to suscriptor dashboard frontend?
- Add PHP code to header section from plugin
- How to change a WordPress term’s slug before saving
- dynamic add_action according to child pages (for homepage control)
- Remove action in a parent theme from the child theme
- Remove action within a class in a parent theme’s includes folder from the child theme
- Action hook save_post for newly created posts – $post object data is all empty
- add_filter to the_content from plugin function
- What hook do I use if I want to update a user profile field when a new user is created?
- How to add custom tab page in backend?
- Add html code in admin page
- What hook should I use that will fire whenever I open a post for editing in the WP back-end?
- Can not using get_header() cause trouble (later on)?
- Is there a author_update action?
- How to set Media Box form elements default value?
- How to get product information using hooks?
- How to read and write session data?
- Print additional fields in wp_new_user_notification_email_admin
- Creating custom post on registration in wordpress?
- Display custom user profile fields in wordpress
- profile_update not supplying old data
- remove_action not working for a function
- Is there no concise way, a library maybe, to help with unhooking class functions and so on?
- Debug a WP install: how to find which functions write post updates during a process (a woocommerce checkout in my case)
- What hook should I use to add post meta data with on update?
- Problem with call_user_func_array front end
- How to I prevent WordPress from switching external HTTP links to HTTPS?
- Stylesheet is getting removed/deregistered automatically
- How to override get_avatar() function?
- WordPress Boilerplate Plugin doesn’t see callback functions for add_settings_field and add_settings_section
- add extra parameter in default hook in wordpress
- Change user role if it’s orders count more than
- Exclude WooCommerce terminations from YOAST
- set_post_format called after wp_update_post when using bulk edit?
- Using actions, hooks and filters in a non-WordPress page
- Hook into create_category
- Trouble adding data to options table
- How to hook into publish_posttype?
- Fire a hook programmatically
- How do I override the user’s input when updating a custom post type’s permalink?
- How to add a new link to the default register form’s footer links?
- $GLOBALS & global doesn’t work [closed]
- Hooks not working on live server
- Callback API for getting response from fygaro payment gateway
- Changing login url