我使用此代码从文本类型元文件中获取数据..这将创建一个数组
$args = array('post_type' => 'locations_add');
$prefix = 'nilgiris_';
$the_query = new WP_Query($args);
if ($the_query->have_posts()):
while ($the_query->have_posts()):
$the_query->the_post();
$l_names[] = rwmb_meta($prefix . 'l_name');
$lo_name = array();
foreach( $l_names as $l_namea ){
$lo_name[] = array(
$l_namea => $l_namea
);
}
endwhile;
endif;
我的问题是,当使用wp_query
函数和metabox时,metabox将无法加载..
她是整个代码
<?php
$args = array('post_type' => 'locations_add');
$prefix = 'nilgiris_';
$the_query = new WP_Query($args);
if ($the_query->have_posts()):
while ($the_query->have_posts()):
$the_query->the_post();
$l_names[] = rwmb_meta($prefix . 'l_name');
$lo_name = array();
foreach( $l_names as $l_namea ){
$lo_name[] = array(
$l_namea => $l_namea
);
}
endwhile;
endif;
add_filter('rwmb_meta_boxes', 'website_register_meta_boxes');
function website_register_meta_boxes($meta_boxes) {
$prefix = 'nilgiris_';
$meta_boxes[] = array(
'id' => 'location_types',
'title' => __('location name', $prefix),
'post_types' => array('locations_add'),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
// List of meta fields
'fields' => array(
array(
'name' => __('Enter Location Name', $prefix),
'id' => "{$prefix}l_name",
'desc' => __('Enter name', $prefix),
'type' => 'text',
//'clone' => true,
),
),
);
$meta_boxes[] = array(
'id' => 'location_types',
'title' => __('location name', $prefix),
'post_types' => array('Hotels'),
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => array(
array(
'name' => __('Enter Location Name', $prefix),
'id' => "{$prefix}H_name",
'desc' => __('Enter name', $prefix),
'type' => 'text',
),
array(
'name' => __('Checkbox list', '$prefix'),
'id' => "{$prefix}H_list",
'type' => 'select',
**'options' => $lo_name,**
),
),
);
return $meta_boxes;
}