サーバーサイド
~/vccw/wordpress/wp-includes/functions.phpに書き足し。 idにはWordPressの投稿idを指定。 CustomFieldTemplateを読み込む。
header("Access-Control-Allow-Origin: *");
add_action('wp_ajax_tell_me', 'tell_me');
add_action('wp_ajax_nopriv_tell_me', 'tell_me');
function tell_me() {
$id = 1677;
$res[1] = get_post_meta($id,'LAT',true);
$res[2] = get_post_meta($id,'ALT',true);
echo json_encode($res, JSON_UNESCAPED_UNICODE);
die();
}
クライアントサイド
~/src/index.htmlに書き足し
<script>
var wp_url_admin_ajax = 'http:/*******.local/wp-admin/admin-ajax.php';
jQuery(function ($){
$.ajax({
crossDomain : true,
type: 'POST',
dataType: 'json',
crossDomain: true,
url: wp_url_admin_ajax,
data: {
action : 'tell_me'
},
success: function(response){
console.log(response);
}
});
});
</script>
[参考]
https://hacknote.jp/archives/17237/
https://hacknote.jp/archives/40493/
注意: index.htmlでは違うドメインのデータを取得することが出来ないのでクロスドメイン設定をする必要があります。


