How do I flush rewrite rules

时间:2019-04-20 作者:Alan

保存或更新任何页面后,如何刷新重写规则?我是个新手,正在努力弄清楚这是怎么回事。

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

1 个回复
SO网友:Antti Koskinen

我和flush_rewrite_rules 功能,但基于usage notes 提及人nmr 我想你也许可以这样做,

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() {
  flush_rewrite_rules();
}

相关推荐