将下拉列表转换为多选复选框在wordpress网站


Convert dropdown into multi select check box in wordpress website

我正在尝试在网站的wordpress主题文件中添加一些自定义编码。

目前以下代码在下拉框中显示值,我想将其转换为多选复选框

<!-- Property Furnishing -->
        <div class="control-group">
            <label for="property-furnishing" class="control-label">
                <?php _e( 'Property Furnishing', 'realexpert' ); ?>
            </label>
            <div class="controls">
                <select name="property-furnishing" class="submit-select">
                <?php
                    $args = array(
                        'type' => 'property',
                        'taxonomy' => 'property-furnishing',
                        'hide_empty' => 0,
                    );
                    $cats = get_categories($args);
                    foreach( $cats as $cat ){
                        if($cat->slug == $pro['furnishing']){
                            $selected = 'selected';
                        }else{
                            $selected = '';
                        }
                        echo '<option value="'.$cat->slug.'" '.$selected.'>'.$cat->name.'</option>';
                    }
                ?>
                </select>
            </div>
        </div>

我试过用这个。这样好吗?

        <form name="property-furnishing[]" class="submit-select">
        <?php
            $args = array(
                'type' => 'property',
                'taxonomy' => 'property-furnishing',
                'hide_empty' => 0,
            );
            $cats = get_categories($args);
            foreach( $cats as $cat ){
                if($cat->slug == $pro['furnishing']){
                    $selected = 'selected';
                }else{
                    $selected = '';
                }
                echo '<input type="checkbox" value="'.$cat->slug.'" '.$selected.'>'.$cat->name.'</input>';
            }
        ?>
        </form>

更改:

<select name="property-furnishing" class="submit-select">

自:

<select multiple name="property-furnishing" class="submit-select">

要从<select>框中获取多条记录,您需要在 <select> 标记中使用multiple=""multiple="multiple"

<select multiple="" name="property-furnishing[]" class="submit-select">

请注意:当您在框中使用多个属性时,您需要将 name 字段用作像 property-furnishing[] 这样的数组,您将在 PHP 中获得SUPER GLOBAL (POST/GET)中的所有选定值。