函数文档

get_all_category_ids()

💡 云策文档标注

概述

get_all_category_ids() 函数用于检索所有分类的 ID,但自 WordPress 4.0.0 起已被弃用,建议使用 get_terms() 替代。

关键要点

  • 函数返回一个整数数组,包含所有分类的 ID。
  • 该函数已被标记为弃用,使用时会触发 _deprecated_function() 警告。
  • 替代方案是使用 get_terms() 函数,并指定 taxonomy 为 'category'、fields 为 'ids'、get 为 'all'。

代码示例

function get_all_category_ids() {
    _deprecated_function( __FUNCTION__, '4.0.0', 'get_terms()' );

    $cat_ids = get_terms(
        array(
            'taxonomy' => 'category',
            'fields'   => 'ids',
            'get'      => 'all',
        )
    );

    return $cat_ids;
}

注意事项

  • 自 WordPress 4.0.0 版本起,此函数已被弃用,开发者应避免在新代码中使用。
  • 相关函数包括 get_terms() 和 _deprecated_function(),用于替代和标记弃用状态。

📄 原文内容

Retrieves all category IDs.

Description

See also

Return

int[] List of all of the category IDs.

Source

function get_all_category_ids() {
	_deprecated_function( __FUNCTION__, '4.0.0', 'get_terms()' );

	$cat_ids = get_terms(
		array(
			'taxonomy' => 'category',
			'fields'   => 'ids',
			'get'      => 'all',
		)
	);

	return $cat_ids;
}

Changelog

Version Description
4.0.0 Deprecated. Use get_terms()
2.0.0 Introduced.