私はワードプレス用のこのプラグインに取り組んでいますが、リセットされないクエリで立ち往生しています。次の関数では:
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 変数は、投稿編集ページのデフォルト値ではなく、このクエリの最新の値に設定されます。
このプラグインの解決方法を知りたいです。すべてを使って私を正しい方向に導くことができました。前もって感謝します!
乾杯、
ロニー