$cats= get_categories(array(
'order' => 'ASC',
'orderby' => 'id',
'hierarchical' => 0,
'hide_empty' => 0,
'taxonomy' => 'edu_year'
));
我想生成一个变量,其中包含从get_categories函数中检索的值的ID数组。
答案 0 :(得分:7)
根据它返回的文档:
$category->term_id
$category->name
$category->slug
$category->term_group
$category->term_taxonomy_id
$category->taxonomy
$category->description
$category->parent
$category->count
$category->cat_ID
$category->category_count
$category->category_description
$category->cat_name
$category->category_nicename
$category->category_parent
所以:
$output_categories = array();
$categories=get_categories($args);
foreach($categories as $category) {
$output_categories[$category->cat_ID] = $category->name;
}
然后$output_categories
正是您所需要的。
答案 1 :(得分:3)
使用get_terms时:
<?php
$categories_ids = get_terms(
array( 'category' ), // Taxonomies
array( 'fields' => 'ids' ) // Fields
);
?>