父术语和子术语分类显示在多选复选框下拉 Wordpress 中

问题描述

我在主题中内置了一些自定义分类法,在分类法下拉菜单中,分类法按层次结构显示。它只是显示所有分类法的下拉列表,但如何将它们显示到多选复选框中?

这就是我所拥有的:

<label><strong>Building / Place Amenities</strong></label>
<?PHP
/** The taxonomy we want to parse */
$taxonomy = "place_amenity_taxonomy";
/** Get all taxonomy terms */
$terms = get_terms($taxonomy,array(
        "orderby" => "count","hide_empty" => false
    )
);
/** Get terms that have children */
$hierarchy = _get_term_hierarchy($taxonomy);
?>
<select name="terms" id="terms">
    <?PHP
    /** Loop through every term */
    foreach ($terms as $term) {
        /** Skip term if it has children */
        if ($term->parent) {
            continue;
        }
        echo '<input type="checkBox" value ="' . $term->name . '">' . $term->name . '</input>';


    }
    ?>
</select>

想要像这样显示分类列表:output

解决方法

不完全确定“但如何将它们显示到多个选择复选框中?”是什么意思,但您可以向选择添加多个并为其返回一组结果<select name="terms" id="terms" multiple>