我在wordpress工作。我从数据库中获取数据并在下拉列表中显示。 我的代码是这样的。
<select multiple="multiple" class="tole_int">
<?php
global $wpdb;
$query_interest = "select p.* from wp_posts as p where p.post_type = 'interests' and p.post_name !='' ";
$tolerancetypes = $wpdb->get_results($query_interest,OBJECT);
foreach($tolerancetypes as $key=>$interest)
{
?>
<option value="<?php echo $interest->ID; ?>"><?php echo ucfirst($interest->post_name); ?></option>
<?php
}
?>
</select>
我写了多个=&#34;多个&#34;选择多个值的属性。但我想添加复选框和值。那我该怎么写?
答案 0 :(得分:1)
试试这个&#34; Bootstrap Multiselect&#34;
http://davidstutz.github.io/bootstrap-multiselect/
然后您不需要手动编写复选框代码。
答案 1 :(得分:0)
如果您要在Form
中使用此复选框,请确保添加metabox
中的复选框,无需创建Form
所以,将selectbox
更改为checkbox
<?php
global $wpdb;
$query_interest = "select p.* from wp_posts as p where p.post_type = 'interests' and p.post_name !='' ";
$tolerancetypes = $wpdb->get_results($query_interest,OBJECT);
foreach($tolerancetypes as $key=>$interest)
{
?>
<input type="checkbox" name="tole_int[]" value="<?php echo $interest->ID; ?>" /><?php echo $interest->post_title; ?>
<?php
}
在提交表单时,您可以获得以逗号分隔的值并保存
$tole_int = implode(",", $_POST['tole_int']);
或者如果要检查多个复选框值的输出,请尝试
echo '<pre>';print_r($_POST['tole_int']);echo '</pre>';