_update_posts_count_on_transition_post_status

函式
_update_posts_count_on_transition_post_status ( $new_status, $old_status, $post = null )
引數
  • (string) $new_status The status the post is changing to.
    Required:
  • (string) $old_status The status the post is changing from.
    Required:
  • (WP_Post) $post Post object
    Required:
    Default: null
定義位置
相關方法
_update_term_count_on_transition_post_statuswp_transition_post_status_transition_post_statusblock_core_calendar_update_has_published_post_on_transition_post_status_update_posts_count_on_delete
引入
4.0.0
棄用
-

_update_posts_count_on_transition_post_status: 當一個文章從一個狀態過渡到另一個狀態時,該函式更新特定術語的文章計數: 當文章被新增、刪除或修改時,它被用來確保文章計數的準確性。

當一個文章的狀態發生變化時,用於更新當前網站的文章數量的處理程式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) {
if ( $new_status === $old_status ) {
return;
}
if ( 'post' !== get_post_type( $post ) ) {
return;
}
if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
return;
}
update_posts_count();
}
function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) { if ( $new_status === $old_status ) { return; } if ( 'post' !== get_post_type( $post ) ) { return; } if ( 'publish' !== $new_status && 'publish' !== $old_status ) { return; } update_posts_count(); }
function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) {
	if ( $new_status === $old_status ) {
		return;
	}

	if ( 'post' !== get_post_type( $post ) ) {
		return;
	}

	if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
		return;
	}

	update_posts_count();
}

常見問題

FAQs
檢視更多 >