wp_count_terms

函式
wp_count_terms ( $args = array(), $deprecated = '' )
引數
  • (array|string) $args Optional. Array or string of arguments. See WP_Term_Query::__construct() for information on accepted arguments. Default empty array.
    Required:
    Default: array()
  • (array|string) $deprecated Optional. Argument array, when using the legacy function parameter format. If present, this parameter will be interpreted as `$args`, and the first function parameter will be parsed as a taxonomy or array of taxonomies. Default empty.
    Required:
    Default: (empty)
返回值
  • (string|WP_Error) Numeric string containing the number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
定義位置
相關方法
wp_count_sitescount_userswp_update_termwp_count_commentswp_set_post_terms
引入
2.3.0
棄用
-

wp_count_terms: 這是一個返回特定分類法中術語數量的函式。它可以用來獲得術語數量的概述,並跟蹤分類法。

計算分類法中的術語數量。

預設的$args是’hide_empty’,可以是’hide_empty=true’或array(‘hide_empty’ => true)。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_count_terms( $args = array(), $deprecated = '' ) {
$use_legacy_args = false;
// Check whether function is used with legacy signature: `$taxonomy` and `$args`.
if ( $args
&& ( is_string( $args ) && taxonomy_exists( $args )
|| is_array( $args ) && wp_is_numeric_array( $args ) )
) {
$use_legacy_args = true;
}
$defaults = array( 'hide_empty' => false );
if ( $use_legacy_args ) {
$defaults['taxonomy'] = $args;
$args = $deprecated;
}
$args = wp_parse_args( $args, $defaults );
// Backward compatibility.
if ( isset( $args['ignore_empty'] ) ) {
$args['hide_empty'] = $args['ignore_empty'];
unset( $args['ignore_empty'] );
}
$args['fields'] = 'count';
return get_terms( $args );
}
function wp_count_terms( $args = array(), $deprecated = '' ) { $use_legacy_args = false; // Check whether function is used with legacy signature: `$taxonomy` and `$args`. if ( $args && ( is_string( $args ) && taxonomy_exists( $args ) || is_array( $args ) && wp_is_numeric_array( $args ) ) ) { $use_legacy_args = true; } $defaults = array( 'hide_empty' => false ); if ( $use_legacy_args ) { $defaults['taxonomy'] = $args; $args = $deprecated; } $args = wp_parse_args( $args, $defaults ); // Backward compatibility. if ( isset( $args['ignore_empty'] ) ) { $args['hide_empty'] = $args['ignore_empty']; unset( $args['ignore_empty'] ); } $args['fields'] = 'count'; return get_terms( $args ); }
function wp_count_terms( $args = array(), $deprecated = '' ) {
	$use_legacy_args = false;

	// Check whether function is used with legacy signature: `$taxonomy` and `$args`.
	if ( $args
		&& ( is_string( $args ) && taxonomy_exists( $args )
			|| is_array( $args ) && wp_is_numeric_array( $args ) )
	) {
		$use_legacy_args = true;
	}

	$defaults = array( 'hide_empty' => false );

	if ( $use_legacy_args ) {
		$defaults['taxonomy'] = $args;
		$args                 = $deprecated;
	}

	$args = wp_parse_args( $args, $defaults );

	// Backward compatibility.
	if ( isset( $args['ignore_empty'] ) ) {
		$args['hide_empty'] = $args['ignore_empty'];
		unset( $args['ignore_empty'] );
	}

	$args['fields'] = 'count';

	return get_terms( $args );
}

常見問題

FAQs
檢視更多 >