admin管理员组文章数量:1023867
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( ) {
flush_rewrite_rules();
}
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( ) {
flush_rewrite_rules();
}
Share
Improve this question
edited Apr 20, 2019 at 22:20
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked Apr 20, 2019 at 21:52
AlanAlan
111 bronze badge
1
- 2 Do not flush rules here. Have a read this "usage" note. – nmr Commented Apr 20, 2019 at 22:52
1 Answer
Reset to default 0I 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() {
flush_rewrite_rules();
}
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( ) {
flush_rewrite_rules();
}
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( ) {
flush_rewrite_rules();
}
Share
Improve this question
edited Apr 20, 2019 at 22:20
fuxia♦
107k39 gold badges255 silver badges459 bronze badges
asked Apr 20, 2019 at 21:52
AlanAlan
111 bronze badge
1
- 2 Do not flush rules here. Have a read this "usage" note. – nmr Commented Apr 20, 2019 at 22:52
1 Answer
Reset to default 0I 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() {
flush_rewrite_rules();
}
本文标签: How do I flush rewrite rules
版权声明:本文标题:How do I flush rewrite rules 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745567781a2156555.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论