问题
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>
回答1:
Get all post categories ordered by count.
String syntax:
$categories = get_terms( 'category', 'orderby=count&hide_empty=0' );
Array syntax:
$categories = get_terms( 'category', array(
'orderby' => 'count',
'hide_empty' => 0,
) );
Get all the links categories:
$mylinks_categories = get_terms( 'link_category', 'orderby=count&hide_empty=0' );
See the documentation.
来源:https://stackoverflow.com/questions/27353650/how-to-replace-deprecated-functions-from-my-wordpress-code