LoginSignup
1
4

More than 5 years have passed since last update.

WordPress WP_REST_API 使い方の基本設定とエンドポイントの勉強

Last updated at Posted at 2018-02-17

WordPress WP_REST_APIを使うのに色々と調べましたのでここに整理していきたいと思います。
関連記事 WordPress WP_REST_APIで投稿データを取得するでサムネイル画像とアドバンスカスタムフイールド画像を出力する
も合わせてみてみてください。

デフォルト

【固定ページ一覧】

https://example.com/wp-json/wp/v2/pages

【投稿ページ一覧】

https://example.com/wp-json/wp/v2/posts

【投稿ページ一覧(サムネイル画像情報を取得)】

https://example.com/wp-json/wp/v2/posts?_embed

カスタム投稿記事を取得

functions.phpでカスタム投稿記事の設定の中に下記の記述を追記する

'show_in_rest' => true,

【カスタム投稿(news)ページ一覧】

https://example.com/wp-json/wp/v2/news

【カスタム投稿(news)ページ一覧(サムネイル画像情報を取得)】

https://example.com/wp-json/wp/v2/news/?_embed

【カスタム投稿(news)ページ最新15件とサムネイル画像群取得】

https://example.com/wp-json/wp/v2/news/?_embed&per_page=15

カスタム投稿のタクソノミー分類された記事を取得

functions.phpでタクソノミー設定の中に下記の記述を追記する

'show_in_rest' => true,

【カスタム投稿(news)ページの在るターム記事の一覧】

https://example.com/wp/v2/news?news_cat=29

【カスタム投稿(news)ページの在るターム記事の最新5件】

https://example.com/wp/v2/news/?news_cat=29&per_page=5

カスタム投稿記事の中のアドバンスカスタムフィールドの値を取得したい場合

プラグインを使います。
【ACF to REST API】をプラグインインストールして有効にするだけでオーケーです。

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4