2014-12-08 68 views
1

WordPress的功能get_all_category_ids()它被弃用,所以我需要更换get_terms(),但我不能让它工作。你能帮我做这个代码在WordPress 4.0上有效吗?如何从我的wordpress代码替换弃用的函数?

<label>Choose category</label> 
<select name="mycategories" >'; 

$category_ids = get_all_category_ids(); 
foreach($category_ids as $cat_id) 
{ 
    $cat_name = get_cat_name($cat_id); 

    if($category == $cat_id) 
    { 
     $html .= '<option selected="selected" value="'.$cat_id.'" '.$cat_name.'>'.$cat_name.'</option>'; 
    } else { 
     $html .= '<option value="'.$cat_id.'" '.$cat_name.'>'.$cat_name.'</option>'; 
    } 
} 
$html.= '</select> 
+0

你能用'get_terms()'显示你试过的东西吗? – rnevius 2014-12-08 08:01:56

回答

2

获取count排序的所有帖子分类。

字符串语法:

$categories = get_terms('category', 'orderby=count&hide_empty=0'); 

数组语法:

$categories = get_terms('category', array(
    'orderby' => 'count', 
    'hide_empty' => 0, 
)); 

获取所有的链接类:

$mylinks_categories = get_terms('link_category', 'orderby=count&hide_empty=0'); 

查看documentation

相关问题