/wp-json/demo/v1/latestを10行前後で追加し、最新投稿の要約JSONを返します。外部サービスやSPAから**軽く叩ける“窓口”**を作る、といった検証に役立ちます。

プラグイン(demo-rest.php)
PHP
<?php
/**
 * Plugin Name: Demo REST Endpoint
 */
add_action('rest_api_init', function () {
  register_rest_route('demo/v1', '/latest', [
    'methods' => 'GET',
    'permission_callback' => '__return_true',
    'callback' => function () {
      $posts = get_posts(['numberposts' => 5]);
      return array_map(fn($p) => [
        'id' => $p->ID,
        'title' => get_the_title($p),
        'link' => get_permalink($p),
        'date' => get_the_date('c', $p),
      ], $posts);
    },
  ]);
});
フロントのfetch例
HTML
<script>
(async () => {
  const res = await fetch('/wp-json/demo/v1/latest');
  const data = await res.json();
  console.table(data);
})();
</script>

permission_callback__return_trueにして公開情報のみ返す
get_postsは軽量。必要に応じてCPTやメタも拡張
・レスポンスはフィールドを厳選し、外部で扱いやすく