我正在为 wordpress 开发这个插件,我被困在一个不会被重置的查询上。在以下函数中:
function WPSM_artists_autocomplete(){
$response = array();
query_posts('post_type=artist&posts_per_page=-1');
if (have_posts()) : while (have_posts()) : the_post();
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'artist-icon');
$image_url = $image_url[0];
$response[] = array( get_the_ID() , get_the_title() , null, '<img src="'.$image_url.'" />'. get_the_title());
endwhile; endif;
wp_reset_query();
// Write JSON file
$output = json_encode($response);
$data = WPSM_CACHE_DIR."/data.json";
$fh = fopen($data, 'w') or die("can't open file");
fwrite($fh, $output);
fclose($fh);
// Return JSON url
echo WPSM_CACHE_URL."/data.json";
}
我使用 query_posts 来填充元框。但是 wp_reset_query(); 似乎无法正常工作。这会影响所有其他元框和发布相关选项。全局 $post 变量设置为此查询的最新值,而不是帖子编辑页面的默认值。
我很想听听如何解决这个插件。可以利用一切使我朝着正确的方向前进。提前致谢!
干杯,
罗尼