WordCamp.orgからスポンサー情報をWP REST APIで取得する

wordcamp.orgでWP REST APIが使えるっぽいのでちょっと触ってみました。 使うクエリ “wcb_sponsor”というクエリを使います。 ちなみにこれと?filter[XXX]は […]

広告ここから
広告ここまで

目次

    wordcamp.orgでWP REST APIが使えるっぽいのでちょっと触ってみました。

    使うクエリ

    “wcb_sponsor”というクエリを使います。
    ちなみにこれと?filter[XXX]は併用できないので要注意です。

    Example: WordCamp US 2015のスポンサー情報を取得する

    $curl -l https://2015.us.wordcamp.org/wp-json/posts?type=wcb_sponsor
    [js]
    $ curl -l https://2015.us.wordcamp.org/wp-json/posts?type=wcb_sponsor | jq ".[0]"
    {
    "ID": 10067,
    "title": "Photobot -3000-",
    "status": "publish",
    "type": "wcb_sponsor",
    "author": {
    "ID": 385876,
    "username": "kcristiano",
    "name": "Kevin Cristiano",
    "first_name": "Kevin",
    "last_name": "Cristiano",
    "nickname": "kcristiano",
    "slug": "kcristiano",
    "URL": "https://tadpole.cc",
    "avatar": "https://secure.gravatar.com/avatar/365c9b6e2477fa5daec3be6db05c8f57?s=96",
    "description": "",
    "registered": "2008-03-08T03:46:28+00:00",
    "meta": {
    "links": {
    "self": "https://2015.us.wordcamp.org/wp-json/users/385876",
    "archives": "https://2015.us.wordcamp.org/wp-json/users/385876/posts"
    }
    }
    },
    "content": "",
    "parent": null,
    "link": "https://2015.us.wordcamp.org/sponsor/photobot-3000/",
    "date": "2015-12-06T08:57:39",
    "modified": "2015-12-06T08:57:39",
    "format": "standard",
    "slug": "photobot-3000",
    "guid": "https://2015.us.wordcamp.org/?post_type=wcb_sponsor&p=10067",
    "excerpt": null,
    "menu_order": 0,
    "comment_status": "closed",
    "ping_status": "closed",
    "sticky": false,
    "date_tz": "America/New_York",
    "date_gmt": "2015-12-06T13:57:39",
    "modified_tz": "America/New_York",
    "modified_gmt": "2015-12-06T13:57:39",
    "meta": {
    "links": {
    "self": "https://2015.us.wordcamp.org/wp-json/posts/10067",
    "author": "https://2015.us.wordcamp.org/wp-json/users/385876",
    "collection": "https://2015.us.wordcamp.org/wp-json/posts",
    "replies": "https://2015.us.wordcamp.org/wp-json/posts/10067/comments",
    "version-history": "https://2015.us.wordcamp.org/wp-json/posts/10067/revisions"
    }
    },
    "terms": {
    "wcb_sponsor_level": [
    {
    "ID": 11,
    "name": "In-Kind",
    "slug": "in-kind",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://2015.us.wordcamp.org/sponsor_level/in-kind/",
    "meta": {
    "links": {
    "collection": "https://2015.us.wordcamp.org/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://2015.us.wordcamp.org/wp-json/taxonomies/wcb_sponsor_level/terms/5542"
    }
    }
    }
    ]
    },
    "post_meta": [
    {
    "ID": 102949,
    "key": "_wcpt_sponsor_website",
    "value": "https://photobot3000.com/"
    }
    ]
    }
    [/js]

    Example2: WordCamp Paris 2016のスポンサーレベルを取得する

    [js]
    $ curl -l https://paris.wordcamp.org/2016/wp-json/posts?type=wcb_sponsor | jq ".[].terms.wcb_sponsor_level"
    [
    {
    "ID": 55,
    "name": "Argent",
    "slug": "argent",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/argent/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4327"
    }
    }
    }
    ]
    [
    {
    "ID": 56,
    "name": "Bronze",
    "slug": "bronze",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/bronze/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4035"
    }
    }
    }
    ]
    [
    {
    "ID": 54,
    "name": "Or",
    "slug": "or",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 1,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/or/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4326"
    }
    }
    }
    ]
    [
    {
    "ID": 56,
    "name": "Bronze",
    "slug": "bronze",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/bronze/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4035"
    }
    }
    }
    ]
    [
    {
    "ID": 55,
    "name": "Argent",
    "slug": "argent",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/argent/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4327"
    }
    }
    }
    ]
    [
    {
    "ID": 53,
    "name": "Platine",
    "slug": "platine",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 2,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/platine/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/213842"
    }
    }
    }
    ]
    [
    {
    "ID": 55,
    "name": "Argent",
    "slug": "argent",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/argent/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4327"
    }
    }
    }
    ]
    [
    {
    "ID": 56,
    "name": "Bronze",
    "slug": "bronze",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 3,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/bronze/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/4035"
    }
    }
    }
    ]
    [
    {
    "ID": 53,
    "name": "Platine",
    "slug": "platine",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 2,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/platine/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/213842"
    }
    }
    }
    ]
    [
    {
    "ID": 4,
    "name": "Splendid Sponsor",
    "slug": "splendid",
    "description": "",
    "taxonomy": "wcb_sponsor_level",
    "parent": null,
    "count": 1,
    "link": "https://paris.wordcamp.org/2016/sponsor_level/splendid/",
    "meta": {
    "links": {
    "collection": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms",
    "self": "https://paris.wordcamp.org/2016/wp-json/taxonomies/wcb_sponsor_level/terms/497030"
    }
    }
    }
    ]
    [/js]

    開発環境で使ってみる

    WordPress Meta EnvironmentにあるWordCampの開発環境には実はWP APIプラグイン入ってません。

    なので開発環境で使ってみたい人は自分でインストールする必要があります

    バージョンに注意

    WordCamp.org では WP API v1が使われてます。
    なので”WordPress REST API (Version 2)”じゃなくて”WP REST API (WP API)”をインストールしないと意図した動きをしてくれません。

    WP-CLIでやる方法

    [bash]
    $ vagrant ssh
    $ cd /vagrant/www/wordpress-meta-environment/wordcamp.dev/public_html/wordpress
    $ wp plugin install json-rest-api –activate
    [/bash]

    一応プルリク投げておいたので、マージしてもらえれば問題なく使えるようになるはずです。

    広告ここから
    広告ここまで
    Home
    Search
    Bookmark