【发布时间】:2018-09-07 08:33:45
【问题描述】:
我想在 wordpress 页面中使用 select 2 进行搜索,并且我想只获得私有页面的结果,我得到了一些 li 正确的“14 li”,这就是我在我的数据库中拥有的,但 li foreach 是空的,为什么?
$post_id = $wpdb->get_results("SELECT `ID`,`post_title` FROM $wpdb->posts WHERE `post_type` = 'page' and `post_status` = 'private'");
?>
<div class="form-group">
<label class="col-md-3 control-label" for="service"><?php echo $lang['department']; ?> *</label>
<div class="col-md-8">
<select name="services[]" id="service" class="form-control select2-multiple" multiple>
<?php if ( !empty( $post_id ) ) {
foreach ( $post_id as $r ) {
?>
<option value="<?php echo $post_id['ID']?>"><?php $post_id['post_title']?></option>
<?php
}
}
?>
</select>
</div>
</div>
<script>
jQuery(document).ready(function() {
jQuery('#service').select2();
});
</script>
【问题讨论】:
-
你跳过
-
“数字”拼写错误
标签: php sql wordpress jquery-select2