如何从我的wordpress代码中替换不推荐使用的功能? [英] How to replace deprecated functions from my wordpress code?
本文介绍了如何从我的wordpress代码中替换不推荐使用的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
WordPress的函数 get_all_category_ids()
已弃用,因此我需要替换为 get_terms()
,但我无法使其工作。您能帮我使此代码在WordPress 4.0上有效吗?
The function get_all_category_ids()
from WordPress it is deprecated so I need to replace with get_terms()
but I can't make it work. Can you please help me to make this code to be valid on WordPress 4.0 ?
<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>
推荐答案
获取按计数排序的所有帖子类别。
字符串语法:
$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' );
请参见文档。
这篇关于如何从我的wordpress代码中替换不推荐使用的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文