我有一个自定义的分类法,我们称之为;指示;。我们将其与自定义帖子类型“配合使用”;产品;。我们对术语Parent->;小孩父级从未与产品建立连接。我使用它来创建一个自定义的select字段,并且需要父字段作为optgroup标题。
是否使用此结构父级
子级1(根据后端的2篇帖子)子级2(根据后端的1篇帖子)
- 但是如果我查询子主题并检查计数,它总是显示为NULL。在Wordpress仪表板中,它使用2和1正确定位。
为什么不在前端呢。
$args = array(
\'hide_empty\' => false,
\'orderby\' => \'name\'
);
$ins = get_terms(\'indikationen\', $args);
if($ins):
echo "<select>";
foreach($ins as $in):
if ( count( get_term_children( $in->term_id, \'indikationen\' ) ) > 0 ):
echo \'<optgroup label="\'.$in->name.\'">\';
foreach($ins as $sub):
if($sub->parent == $in->term_id):
echo "<option value=\'".$sub->term_id."\'>".$sub->name. " count: ".$sub->count."</option>";
// SUB-COUNT is always NULL but has correct count in backend
endif;
endforeach;
echo \'</optgroup>\';
else:
if($in->count):
echo "<option value=\'".$in->term_id."\'>" .$in->name. " (".$in->count.")</option>";
endif;
endif;
endforeach;
echo "</select>";
endif;
我做错了什么?var_dump($sub);
// shows me for count also NULL
谢谢