LoginSignup
11
5

More than 5 years have passed since last update.

wordpress 4.7でREST-APIの仕様が変更になったので合わせる

Last updated at Posted at 2016-12-22

問題

wordpress 4.7でRest APIの仕様が変わっていてそれまでfilterを使っていた記事の選択取得が出来ない。

After updating to WordPress 4.7 WP REST api v2 endpoints stopped filtering. Any one else experiencing this? Any solutions?
http://stackoverflow.com/questions/41124246/wp-v4-7-rest-api-v2-endpoints-stopped-filtering

彼も困っている

対処

対処前
http://wocker.dev/wp/v2/posts?filter[category_name]=foo&_embed
静的ページもカテゴリも何もかもfilterだった

対処後
http://wocker.dev/posts?category=数字
のように引数にカテゴリIDを与える

1.
http://wocker.dev/wp-json/wp/v2/categories?slug=slug_name
からカテゴリIDを取得し

2.
http://wocker.dev/wp-json/wp/v2/posts?categories=4
指定したIDのpostsを取得

slug指定方法が見つかっていないので現状こうしている。
パーマリンクを数字ベースにしても良いのであれば1省略出来そう

詳しくは
https://developer.wordpress.org/rest-api/reference/posts/


ということで数少ないWP+MVCフレームワーク実例であるwcus-demoテーマも修正しないと動かない
(underscore.jsのtemplate仕様変更による動かない問題もあったと記憶)
https://github.com/rachelbaker/wcus-demo

11
5
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
11
5