我有以下代码来填充重力表单中的复选框字段。我有一个field\\u id数组,通过foreach循环循环。$arr = array(5, 6, 7, 8, 9);
然后,我有了第二个foreach循环,其中包含一个从数据库中提取数据的查询。
但是,代码正在运行,每个后续的field\\u id都显示该field\\u id和之前的field\\u id的结果。例如field\\u id=6显示field\\u id=5和field\\u id=6的复选框字段列表。field\\u id=7显示field\\u id=5、field\\u id=6和field\\u id=7等的复选框字段列表。
function populate_checkboxes( $form ){
foreach( $form[\'fields\'] as &$field ) {
$arr = array(5, 6, 7, 8, 9);
foreach($arr as $field_id){
global $wpdb;
$query = $wpdb->get_results( "SELECT sefer FROM bulk_import where field_id_select_items = {$field_id}" );
foreach($query as $sefer){
if ( $field->id != $field_id ) {continue;}
$choices[] = array( \'text\' => \'Select All\', \'value\' => \'Select_all\' );
$inputs[] = array( \'label\' => \'Select All\', \'id\' => \'1\');
//get all $sefer values
$posts = get_posts(array(
\'post_type\'=> array(\'learning_item\'), \'suppress_filters\' => 0, \'posts_per_page\' => -1, \'order\' => \'asc\',
\'meta_query\' => array(
array( \'key\' => \'taken\', \'value\' => \'0\'),
array(\'key\' => \'torah\', \'value\' => $sefer -> sefer)
),
));
$input_id = 2;
foreach( $posts as $post ) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if ( $input_id % 10 == 0 ) {$input_id++;}
$choices[] = array( \'text\' => $post->post_title, \'value\' => $post->post_title );
$inputs[] = array( \'label\' => $post->post_title, \'id\' => "{$field_id}.{$input_id}" );
$input_id++;
}
$field->choices = $choices;
$field->inputs = $inputs;
}
//reset query here?
wp_reset_query();
}
}
return $form;}
是否需要在某个位置重置查询?我尝试添加wp\\u reset\\u query();在几个不同的地方,但都不起作用。我需要在哪里重置查询?