描述:

获取博客所有的分类id集合

用法:

<?php get_all_category_ids() ?>

参数:

None

示例:

<?php
$category_ids = get_all_category_ids();
foreach($category_ids as $cat_id) {
  $cat_name = get_cat_name($cat_id);
  echo $cat_id . ': ' . $cat_name;
}
?>

源文件:

function get_all_category_ids() {
    _deprecated_function( __FUNCTION__, '4.0.0', 'get_terms()' );
 
    if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category' ) ) {
        $cat_ids = get_terms(
            array(
                'taxonomy' => 'category',
                'fields'   => 'ids',
                'get'      => 'all',
            )
        );
        wp_cache_add( 'all_category_ids', $cat_ids, 'category' );
    }
 
    return $cat_ids;
}

 

参与评论