我在stackexchange-->中找到了一段代码,可以在自定义类型的元框中创建一个“列表”,但是,除了输入字段(来自CODEX的示例页面:http://codex.wordpress.org/Function_Reference/add_meta_box), 函数内的WP\\u查询是否有问题?
你能告诉我解决这个问题的魔法是什么吗?在回调函数中,我添加了以下代码:
function myplugin_inner_custom_box() {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), \'myplugin_noncename\' );
// The actual fields for data entry
echo \'<label for="myplugin_new_field">\';
_e("Description for this field", \'myplugin_textdomain\' );
echo \'</label> \';
echo \'<input type="text" id="myplugin_new_field" name="myplugin_new_field"/>\';
$s_query = new WP_Query( array(
\'suppress_filters\' => false,
\'post_type\' => \'movies\'));
while($s_query->have_posts()):$s_query->the_post();
$sname = $post->post_title;
$s_output2 =\'\';
$s_output2 .= \'<option value="\'.$post->ID.\'" >\';
$s_output2 .= $post->post_title;
$s_output2 .= \'</option>\';
echo $s_output2;
endwhile ;
wp_reset_query();
}
但正如我所说,“列表”没有出现。你能帮帮我吗?
最合适的回答,由SO网友:Bainternet 整理而成
您缺少HTML select tag 他的孩子有哪些选择,请添加以下内容:
function myplugin_inner_custom_box() {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), \'myplugin_noncename\' );
// The actual fields for data entry
echo \'<label for="myplugin_new_field">\';
_e("Description for this field", \'myplugin_textdomain\' );
echo \'</label> \';
echo \'<input type="text" id="myplugin_new_field" name="myplugin_new_field"/>\';
//the actual select tag
echo \'<label for="my_list_field">\';
_e("Description for this field", \'myplugin_textdomain\' );
echo \'</label> \';
echo \'<select name="my_list_field" id="my_list_field">\';
$s_query = new WP_Query( array(
\'suppress_filters\' => false,
\'post_type\' => \'movies\'));
while($s_query->have_posts()):$s_query->the_post();
$sname = $post->post_title;
$s_output2 =\'\';
$s_output2 .= \'<option value="\'.$post->ID.\'" >\';
$s_output2 .= $post->post_title;
$s_output2 .= \'</option>\';
echo $s_output2;
endwhile ;
echo \'</select>\';
wp_reset_query();
}