_update_term_count_on_transition_post_status

函式
_update_term_count_on_transition_post_status ( $new_status, $old_status, $post )
Access
Private
引數
  • (string) $new_status New post status.
    Required:
  • (string) $old_status Old post status.
    Required:
  • (WP_Post) $post Post object.
    Required:
定義位置
相關方法
_update_posts_count_on_transition_post_statuswp_transition_post_status_transition_post_statusblock_core_calendar_update_has_published_post_on_transition_post_statuswp_update_term_count_now
引入
3.3.0
棄用
-

_update_term_count_on_transition_post_status: 當一個文章從一個狀態過渡到另一個狀態時,這個函式更新特定分類法的術語計數。它用於確保當文章被新增、刪除或修改時,分類法的術語計數是準確的。

當一個文章的狀態改變時,更新自定義分類法的術語計數。

例如,預設的文章術語計數(針對自定義分類法)不包括 私密/草稿帖。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
// Update counts for the post's terms.
foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
$tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
wp_update_term_count( $tt_ids, $taxonomy );
}
}
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { // Update counts for the post's terms. foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); wp_update_term_count( $tt_ids, $taxonomy ); } }
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
	// Update counts for the post's terms.
	foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
		$tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
		wp_update_term_count( $tt_ids, $taxonomy );
	}
}

常見問題

FAQs
檢視更多 >