我没办法get_terms()
返回空条件,我已经尝试了很多方法。
代码如下:
$terms = get_terms(\'device\',array(\'hide_empty\' => 0));
foreach($terms as $term) {
if($term->parent == 0) {
if($i++ != 0) echo \'</optgroup>\'; echo \'<optgroup label="\'.$term->name.\'">\';
$id = $term->term_id;
$args = array("child_of"=>$id);
$this_term = get_terms(\'device\',$args);
foreach($this_term as $the_term) {
$term_name = str_replace($term->name,\'\',$the_term->name);
echo \'<option value="\'.$the_term->term_id.\'">\'.$the_term->name.\'</option>\';
}
}
}
我已经尝试了所有可能的方法:$terms = get_terms(\'device\',array(\'hide_empty\' => false))
$terms = get_terms(\'device\',array(\'hide_empty\' => 0))
$terms = get_terms(\'device\',array(\'hide_empty=false\'))
$terms = get_terms(\'device\',array(\'hide_empty=0\'))
也尝试了最后两种方法array
. 似乎什么都没用。它返回所有有帖子的术语,但没有空的。