Ajex通信のサーバー側の処理について

function.phpに


add_action('wp_ajax_tell_me', 'tell_me'); add_action('wp_ajax_nopriv_tell_me', 'tell_me'); function tell_me() { $id=16; $res[0] = get_the_title($id); $res[1] = get_post_meta($id,"a",true); $res[2] = get_post_meta($id,"b",true); $res[3] = get_post_meta($id,"c",true); $res[4] = get_post_meta($id,"lat",true); $res[5] = get_post_meta($id,"lng",true); echo json_encode($res, JSON_UNESCAPED_UNICODE); header("Access-Control-Allow-Origin: *"); die();

と追記し、指定されたIDの記事データをjson形式に格納して、送ることができる。