How can I flush rewrite rules after saving or updating any page? Pretty much a newbie and trying to figure out how this would work.

add_action( 'save_post', 'my_save_post_function', 10, 3 );
function my_save_post_function( ) {

I haven't worked much with flush_rewrite_rules function, but based on the usage notes mention by nmr I think you could perhaps do something like this,

add_action( 'save_post', 'my_save_post_function' );
function my_save_post_function( $post_id ) {
  $maybe_some_extra_logic = true; // if applicable
  if ( $maybe_some_extra_logic && ! has_action( 'shutdown', 'my_flush_rewrite_rules' ) ) {
    add_action( 'shutdown', 'my_flush_rewrite_rules', 9999 ); // set suitable priority

function my_flush_rewrite_rules() {
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.