wp_count_terms()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_count_terms( array|string $args = array(), array|string $deprecated = '' ): string|WP_Error
Описание
$args по умолчанию равно «hide_empty», что может быть «hide_empty=true» или array(‘hide_empty’ => true).
{@internal Параметр $deprecated разбирается только для обратной совместимости.}
Оригинал (английский)
Default $args is ‘hide_empty’ which can be ‘hide_empty=true’ or array(‘hide_empty’ => true).
{@internal The $deprecated parameter is parsed for backward compatibility only.}
Параметры
$args
array|string
необязательный
= array()
$deprecated
array|string
необязательный
= ''
Возвращаемое значение
string|WP_Error
Исходный код
wp-includes/taxonomy.php:1950
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 );
}
История изменений
| Версия | Описание |
|---|---|
| 5.6.0 | Changed the function signature so that the $args array can be provided as the first parameter. |
| 2.3.0 | Introduced. |

