wp_update_term_count

函式
wp_update_term_count ( $terms, $taxonomy, $do_deferred = false )
引數
  • (int|array) $terms The term_taxonomy_id of the terms.
    Required:
  • (string) $taxonomy The context of the term.
    Required:
  • (bool) $do_deferred Whether to flush the deferred term counts too. Default false.
    Required:
    Default: false
返回值
  • (bool) If no terms will return false, and if successful will return true.
定義位置
相關方法
wp_update_term_count_nowwp_update_user_counts_update_post_term_countwp_update_termwp_update_network_counts
引入
2.3.0
棄用
-

wp_update_term_count是一個更新WordPress資料庫中某一術語計數的函式: 這個函式用來跟蹤屬於某個特定術語的文章的數量,它通常在一個文章被更新或刪除後執行。

更新分類法中的術語數量。

如果有一個分類法的回撥,那麼它將被呼叫以更新計數。

預設動作是計算有術語ID關係的術語數量。一旦完成,就會更新資料庫。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) {
static $_deferred = array();
if ( $do_deferred ) {
foreach ( (array) array_keys( $_deferred ) as $tax ) {
wp_update_term_count_now( $_deferred[ $tax ], $tax );
unset( $_deferred[ $tax ] );
}
}
if ( empty( $terms ) ) {
return false;
}
if ( ! is_array( $terms ) ) {
$terms = array( $terms );
}
if ( wp_defer_term_counting() ) {
if ( ! isset( $_deferred[ $taxonomy ] ) ) {
$_deferred[ $taxonomy ] = array();
}
$_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) );
return true;
}
return wp_update_term_count_now( $terms, $taxonomy );
}
function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) { static $_deferred = array(); if ( $do_deferred ) { foreach ( (array) array_keys( $_deferred ) as $tax ) { wp_update_term_count_now( $_deferred[ $tax ], $tax ); unset( $_deferred[ $tax ] ); } } if ( empty( $terms ) ) { return false; } if ( ! is_array( $terms ) ) { $terms = array( $terms ); } if ( wp_defer_term_counting() ) { if ( ! isset( $_deferred[ $taxonomy ] ) ) { $_deferred[ $taxonomy ] = array(); } $_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) ); return true; } return wp_update_term_count_now( $terms, $taxonomy ); }
function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) {
	static $_deferred = array();

	if ( $do_deferred ) {
		foreach ( (array) array_keys( $_deferred ) as $tax ) {
			wp_update_term_count_now( $_deferred[ $tax ], $tax );
			unset( $_deferred[ $tax ] );
		}
	}

	if ( empty( $terms ) ) {
		return false;
	}

	if ( ! is_array( $terms ) ) {
		$terms = array( $terms );
	}

	if ( wp_defer_term_counting() ) {
		if ( ! isset( $_deferred[ $taxonomy ] ) ) {
			$_deferred[ $taxonomy ] = array();
		}
		$_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) );
		return true;
	}

	return wp_update_term_count_now( $terms, $taxonomy );
}

常見問題

FAQs
檢視更多 >