I am trying to add some custom coding in my website’s wordpress theme files.
Currently the following code displays the value in dropdown box, i want to convert it into multiselect check box
<!-- 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>
I tried using this. Is this fine ?
<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>
Change:
to:
For getting multiple records from a
<select>
box you need to usemultiple=""
ormultiple="multiple"
inside the<select>
tag as:Note that: when you use multiple attribute in box you need to use name field as an array like
property-furnishing[]
and you will get the all selected values in yourSUPER GLOBAL (POST/GET)
inPHP
.