投稿(Posts)

2020.03.23 2020.03.27

TOPICS

翻訳元記事はこちらです。

レスポンスのサンプル

スキーマ

$ curl -X OPTIONS  https://demo.wp-api.org/wp-json/wp/v2/posts
{
  "namespace": "wp/v2",
  "methods": [
    "GET",
    "POST"
  ],
  "endpoints": [
    {
      "methods": [
        "GET"
      ],
      "args": {
        "context": {
          "required": false,
          "default": "view",
          "enum": [
            "view",
            "embed",
            "edit"
          ],
          "description": "Scope under which the request is made; determines fields present in response.",
          "type": "string"
        },
        "page": {
          "required": false,
          "default": 1,
          "description": "Current page of the collection.",
          "type": "integer"
        },
        "per_page": {
          "required": false,
          "default": 10,
          "description": "Maximum number of items to be returned in result set.",
          "type": "integer"
        },
        "search": {
          "required": false,
          "description": "Limit results to those matching a string.",
          "type": "string"
        },
        "after": {
          "required": false,
          "description": "Limit response to posts published after a given ISO8601 compliant date.",
          "type": "string"
        },
        "author": {
          "required": false,
          "default": [],
          "description": "Limit result set to posts assigned to specific authors.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "author_exclude": {
          "required": false,
          "default": [],
          "description": "Ensure result set excludes posts assigned to specific authors.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "before": {
          "required": false,
          "description": "Limit response to posts published before a given ISO8601 compliant date.",
          "type": "string"
        },
        "exclude": {
          "required": false,
          "default": [],
          "description": "Ensure result set excludes specific IDs.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "include": {
          "required": false,
          "default": [],
          "description": "Limit result set to specific IDs.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "offset": {
          "required": false,
          "description": "Offset the result set by a specific number of items.",
          "type": "integer"
        },
        "order": {
          "required": false,
          "default": "desc",
          "enum": [
            "asc",
            "desc"
          ],
          "description": "Order sort attribute ascending or descending.",
          "type": "string"
        },
        "orderby": {
          "required": false,
          "default": "date",
          "enum": [
            "author",
            "date",
            "id",
            "include",
            "modified",
            "parent",
            "relevance",
            "slug",
            "include_slugs",
            "title"
          ],
          "description": "Sort collection by object attribute.",
          "type": "string"
        },
        "slug": {
          "required": false,
          "description": "Limit result set to posts with one or more specific slugs.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "status": {
          "required": false,
          "default": "publish",
          "description": "Limit result set to posts assigned one or more statuses.",
          "type": "array",
          "items": {
            "enum": [
              "publish",
              "future",
              "draft",
              "pending",
              "private",
              "trash",
              "auto-draft",
              "inherit",
              "request-pending",
              "request-confirmed",
              "request-failed",
              "request-completed",
              "wp_stream_enabled",
              "wp_stream_disabled",
              "any"
            ],
            "type": "string"
          }
        },
        "categories": {
          "required": false,
          "default": [],
          "description": "Limit result set to all items that have the specified term assigned in the categories taxonomy.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "categories_exclude": {
          "required": false,
          "default": [],
          "description": "Limit result set to all items except those that have the specified term assigned in the categories taxonomy.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "tags": {
          "required": false,
          "default": [],
          "description": "Limit result set to all items that have the specified term assigned in the tags taxonomy.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "tags_exclude": {
          "required": false,
          "default": [],
          "description": "Limit result set to all items except those that have the specified term assigned in the tags taxonomy.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "sticky": {
          "required": false,
          "description": "Limit result set to items that are sticky.",
          "type": "boolean"
        }
      }
    },
    {
      "methods": [
        "POST"
      ],
      "args": {
        "date": {
          "required": false,
          "description": "The date the object was published, in the site's timezone.",
          "type": [
            "string",
            "null"
          ]
        },
        "date_gmt": {
          "required": false,
          "description": "The date the object was published, as GMT.",
          "type": [
            "string",
            "null"
          ]
        },
        "slug": {
          "required": false,
          "description": "An alphanumeric identifier for the object unique to its type.",
          "type": "string"
        },
        "status": {
          "required": false,
          "enum": [
            "publish",
            "future",
            "draft",
            "pending",
            "private",
            "wp_stream_enabled",
            "wp_stream_disabled"
          ],
          "description": "A named status for the object.",
          "type": "string"
        },
        "password": {
          "required": false,
          "description": "A password to protect access to the content and excerpt.",
          "type": "string"
        },
        "title": {
          "required": false,
          "description": "The title for the object.",
          "type": "object"
        },
        "content": {
          "required": false,
          "description": "The content for the object.",
          "type": "object"
        },
        "author": {
          "required": false,
          "description": "The ID for the author of the object.",
          "type": "integer"
        },
        "excerpt": {
          "required": false,
          "description": "The excerpt for the object.",
          "type": "object"
        },
        "featured_media": {
          "required": false,
          "description": "The ID of the featured media for the object.",
          "type": "integer"
        },
        "comment_status": {
          "required": false,
          "enum": [
            "open",
            "closed"
          ],
          "description": "Whether or not comments are open on the object.",
          "type": "string"
        },
        "ping_status": {
          "required": false,
          "enum": [
            "open",
            "closed"
          ],
          "description": "Whether or not the object can be pinged.",
          "type": "string"
        },
        "format": {
          "required": false,
          "enum": [
            "standard",
            "aside",
            "chat",
            "gallery",
            "link",
            "image",
            "quote",
            "status",
            "video",
            "audio"
          ],
          "description": "The format for the object.",
          "type": "string"
        },
        "meta": {
          "required": false,
          "description": "Meta fields.",
          "type": "object"
        },
        "sticky": {
          "required": false,
          "description": "Whether or not the object should be treated as sticky.",
          "type": "boolean"
        },
        "template": {
          "required": false,
          "description": "The theme file to use to display the object.",
          "type": "string"
        },
        "categories": {
          "required": false,
          "description": "The terms assigned to the object in the category taxonomy.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "tags": {
          "required": false,
          "description": "The terms assigned to the object in the post_tag taxonomy.",
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "ab_test_titles": {
          "required": false,
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "ab_tests": {
          "required": false,
          "type": "object"
        }
      }
    }
  ],
  "schema": {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "post",
    "type": "object",
    "properties": {
      "date": {
        "description": "The date the object was published, in the site's timezone.",
        "type": [
          "string",
          "null"
        ],
        "format": "date-time",
        "context": [
          "view",
          "edit",
          "embed"
        ]
      },
      "date_gmt": {
        "description": "The date the object was published, as GMT.",
        "type": [
          "string",
          "null"
        ],
        "format": "date-time",
        "context": [
          "view",
          "edit"
        ]
      },
      "guid": {
        "description": "The globally unique identifier for the object.",
        "type": "object",
        "context": [
          "view",
          "edit"
        ],
        "readonly": true,
        "properties": {
          "raw": {
            "description": "GUID for the object, as it exists in the database.",
            "type": "string",
            "context": [
              "edit"
            ],
            "readonly": true
          },
          "rendered": {
            "description": "GUID for the object, transformed for display.",
            "type": "string",
            "context": [
              "view",
              "edit"
            ],
            "readonly": true
          }
        }
      },
      "id": {
        "description": "Unique identifier for the object.",
        "type": "integer",
        "context": [
          "view",
          "edit",
          "embed"
        ],
        "readonly": true
      },
      "link": {
        "description": "URL to the object.",
        "type": "string",
        "format": "uri",
        "context": [
          "view",
          "edit",
          "embed"
        ],
        "readonly": true
      },
      "modified": {
        "description": "The date the object was last modified, in the site's timezone.",
        "type": "string",
        "format": "date-time",
        "context": [
          "view",
          "edit"
        ],
        "readonly": true
      },
      "modified_gmt": {
        "description": "The date the object was last modified, as GMT.",
        "type": "string",
        "format": "date-time",
        "context": [
          "view",
          "edit"
        ],
        "readonly": true
      },
      "slug": {
        "description": "An alphanumeric identifier for the object unique to its type.",
        "type": "string",
        "context": [
          "view",
          "edit",
          "embed"
        ]
      },
      "status": {
        "description": "A named status for the object.",
        "type": "string",
        "enum": [
          "publish",
          "future",
          "draft",
          "pending",
          "private",
          "wp_stream_enabled",
          "wp_stream_disabled"
        ],
        "context": [
          "view",
          "edit"
        ]
      },
      "type": {
        "description": "Type of Post for the object.",
        "type": "string",
        "context": [
          "view",
          "edit",
          "embed"
        ],
        "readonly": true
      },
      "password": {
        "description": "A password to protect access to the content and excerpt.",
        "type": "string",
        "context": [
          "edit"
        ]
      },
      "permalink_template": {
        "description": "Permalink template for the object.",
        "type": "string",
        "context": [
          "edit"
        ],
        "readonly": true
      },
      "generated_slug": {
        "description": "Slug automatically generated from the object title.",
        "type": "string",
        "context": [
          "edit"
        ],
        "readonly": true
      },
      "title": {
        "description": "The title for the object.",
        "type": "object",
        "context": [
          "view",
          "edit",
          "embed"
        ],
        "properties": {
          "raw": {
            "description": "Title for the object, as it exists in the database.",
            "type": "string",
            "context": [
              "edit"
            ]
          },
          "rendered": {
            "description": "HTML title for the object, transformed for display.",
            "type": "string",
            "context": [
              "view",
              "edit",
              "embed"
            ],
            "readonly": true
          }
        }
      },
      "content": {
        "description": "The content for the object.",
        "type": "object",
        "context": [
          "view",
          "edit"
        ],
        "properties": {
          "raw": {
            "description": "Content for the object, as it exists in the database.",
            "type": "string",
            "context": [
              "edit"
            ]
          },
          "rendered": {
            "description": "HTML content for the object, transformed for display.",
            "type": "string",
            "context": [
              "view",
              "edit"
            ],
            "readonly": true
          },
          "block_version": {
            "description": "Version of the content block format used by the object.",
            "type": "integer",
            "context": [
              "edit"
            ],
            "readonly": true
          },
          "protected": {
            "description": "Whether the content is protected with a password.",
            "type": "boolean",
            "context": [
              "view",
              "edit",
              "embed"
            ],
            "readonly": true
          }
        }
      },
      "author": {
        "description": "The ID for the author of the object.",
        "type": "integer",
        "context": [
          "view",
          "edit",
          "embed"
        ]
      },
      "excerpt": {
        "description": "The excerpt for the object.",
        "type": "object",
        "context": [
          "view",
          "edit",
          "embed"
        ],
        "properties": {
          "raw": {
            "description": "Excerpt for the object, as it exists in the database.",
            "type": "string",
            "context": [
              "edit"
            ]
          },
          "rendered": {
            "description": "HTML excerpt for the object, transformed for display.",
            "type": "string",
            "context": [
              "view",
              "edit",
              "embed"
            ],
            "readonly": true
          },
          "protected": {
            "description": "Whether the excerpt is protected with a password.",
            "type": "boolean",
            "context": [
              "view",
              "edit",
              "embed"
            ],
            "readonly": true
          }
        }
      },
      "featured_media": {
        "description": "The ID of the featured media for the object.",
        "type": "integer",
        "context": [
          "view",
          "edit",
          "embed"
        ]
      },
      "comment_status": {
        "description": "Whether or not comments are open on the object.",
        "type": "string",
        "enum": [
          "open",
          "closed"
        ],
        "context": [
          "view",
          "edit"
        ]
      },
      "ping_status": {
        "description": "Whether or not the object can be pinged.",
        "type": "string",
        "enum": [
          "open",
          "closed"
        ],
        "context": [
          "view",
          "edit"
        ]
      },
      "format": {
        "description": "The format for the object.",
        "type": "string",
        "enum": [
          "standard",
          "aside",
          "chat",
          "gallery",
          "link",
          "image",
          "quote",
          "status",
          "video",
          "audio"
        ],
        "context": [
          "view",
          "edit"
        ]
      },
      "meta": {
        "description": "Meta fields.",
        "type": "object",
        "context": [
          "view",
          "edit"
        ],
        "properties": {
          "assignees": {
            "type": "array",
            "items": {
              "type": "integer",
              "description": "The assignees user IDs for this post.",
              "default": 0
            }
          }
        }
      },
      "sticky": {
        "description": "Whether or not the object should be treated as sticky.",
        "type": "boolean",
        "context": [
          "view",
          "edit"
        ]
      },
      "template": {
        "description": "The theme file to use to display the object.",
        "type": "string",
        "context": [
          "view",
          "edit"
        ]
      },
      "categories": {
        "description": "The terms assigned to the object in the category taxonomy.",
        "type": "array",
        "items": {
          "type": "integer"
        },
        "context": [
          "view",
          "edit"
        ]
      },
      "tags": {
        "description": "The terms assigned to the object in the post_tag taxonomy.",
        "type": "array",
        "items": {
          "type": "integer"
        },
        "context": [
          "view",
          "edit"
        ]
      },
      "ab_test_titles": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "ab_tests": {
        "type": "object",
        "patternProperties": {
          ".*": {
            "type": "object",
            "properties": {
              "started": {
                "type": "boolean"
              },
              "start_time": {
                "type": "integer"
              },
              "end_time": {
                "type": "integer"
              },
              "traffic_percentage": {
                "type": "number"
              },
              "paused": {
                "type": "boolean"
              },
              "results": {
                "type": "object",
                "required": false,
                "readOnly": true,
                "properties": {
                  "timestamp": {
                    "type": "integer"
                  },
                  "winning": {
                    "type": "integer"
                  },
                  "winner": {
                    "type": "integer"
                  },
                  "aggs": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "variants": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "value": {
                          "type": [
                            "number",
                            "string"
                          ],
                          "description": "Variant value"
                        },
                        "size": {
                          "type": "integer",
                          "default": 0,
                          "description": "Variant sample size"
                        },
                        "hits": {
                          "type": "integer",
                          "default": 0,
                          "description": "Variant conversion count"
                        },
                        "rate": {
                          "type": "number",
                          "default": 0,
                          "description": "Variant conversion rate"
                        },
                        "p": {
                          "type": "number",
                          "default": 1,
                          "description": "Variant p-value"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "links": [
      {
        "rel": "https://api.w.org/action-publish",
        "title": "The current user can publish this post.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "publish",
                "future"
              ]
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-unfiltered-html",
        "title": "The current user can post unfiltered HTML markup and JavaScript.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "content": {
              "raw": {
                "type": "string"
              }
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-sticky",
        "title": "The current user can sticky this post.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "sticky": {
              "type": "boolean"
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-assign-author",
        "title": "The current user can change the author on this post.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "author": {
              "type": "integer"
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-assign-categories",
        "title": "The current user can assign terms in the category taxonomy.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "categories": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-create-categories",
        "title": "The current user can create terms in the category taxonomy.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "categories": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-assign-tags",
        "title": "The current user can assign terms in the post_tag taxonomy.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "tags": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          }
        }
      },
      {
        "rel": "https://api.w.org/action-create-tags",
        "title": "The current user can create terms in the post_tag taxonomy.",
        "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/{id}",
        "targetSchema": {
          "type": "object",
          "properties": {
            "tags": {
              "type": "array",
              "items": {
                "type": "integer"
              }
            }
          }
        }
      }
    ]
  },
  "_links": {
    "self": "https://demo.wp-api.org/wp-json/wp/v2/posts"
  }
}

投稿リスト

$ curl https://demo.wp-api.org/wp-json/wp/v2/posts?per_page=2
[
  {
    "id": 125,
    "date": "2020-01-05T21:39:15",
    "date_gmt": "2020-01-05T21:39:15",
    "guid": {
      "rendered": "https://demo.wp-api.org/2020/01/05/testing-2/"
    },
    "modified": "2020-02-21T13:09:19",
    "modified_gmt": "2020-02-21T13:09:19",
    "slug": "testing-2",
    "status": "publish",
    "type": "post",
    "link": "https://demo.wp-api.org/2020/01/05/testing-2/",
    "title": {
      "rendered": "Testing"
    },
    "content": {
      "rendered": "<p>This is a test.</p>\n",
      "protected": false
    },
    "excerpt": {
      "rendered": "<p>This is a test.</p>\n",
      "protected": false
    },
    "author": 103,
    "featured_media": 0,
    "comment_status": "open",
    "ping_status": "open",
    "sticky": false,
    "template": "",
    "format": "standard",
    "meta": {
      "assignees": []
    },
    "categories": [
      1
    ],
    "tags": [],
    "ab_test_titles": [],
    "prepublish_checks": {},
    "ab_tests": {
      "titles": {
        "started": true,
        "start_time": 1578264763000,
        "end_time": 1580856763000,
        "traffic_percentage": 0,
        "paused": true,
        "results": {
          "0": ""
        }
      }
    },
    "_links": {
      "self": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/125"
        }
      ],
      "collection": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts"
        }
      ],
      "about": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/types/post"
        }
      ],
      "author": [
        {
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/users/103"
        }
      ],
      "replies": [
        {
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/comments?post=125"
        }
      ],
      "version-history": [
        {
          "count": 1,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/125/revisions"
        }
      ],
      "predecessor-version": [
        {
          "id": 126,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/125/revisions/126"
        }
      ],
      "wp:attachment": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/media?parent=125"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "category",
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories?post=125"
        },
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/tags?post=125"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 122,
    "date": "2020-01-05T20:46:15",
    "date_gmt": "2020-01-05T20:46:15",
    "guid": {
      "rendered": "https://demo.wp-api.org/2020/01/05/testing/"
    },
    "modified": "2020-01-05T20:46:15",
    "modified_gmt": "2020-01-05T20:46:15",
    "slug": "testing",
    "status": "publish",
    "type": "post",
    "link": "https://demo.wp-api.org/2020/01/05/testing/",
    "title": {
      "rendered": "Testing"
    },
    "content": {
      "rendered": "<p>This is a test of the emergency broadcast system.</p>\n",
      "protected": false
    },
    "excerpt": {
      "rendered": "<p>This is a test of the emergency broadcast system.</p>\n",
      "protected": false
    },
    "author": 103,
    "featured_media": 0,
    "comment_status": "open",
    "ping_status": "open",
    "sticky": false,
    "template": "",
    "format": "standard",
    "meta": {
      "assignees": []
    },
    "categories": [
      1
    ],
    "tags": [],
    "ab_test_titles": [],
    "prepublish_checks": {},
    "ab_tests": {
      "titles": {
        "started": false,
        "start_time": 1585284350000,
        "end_time": 1587876350000,
        "traffic_percentage": 0,
        "paused": true,
        "results": {
          "0": ""
        }
      }
    },
    "_links": {
      "self": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/122"
        }
      ],
      "collection": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts"
        }
      ],
      "about": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/types/post"
        }
      ],
      "author": [
        {
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/users/103"
        }
      ],
      "replies": [
        {
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/comments?post=122"
        }
      ],
      "version-history": [
        {
          "count": 0,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts/122/revisions"
        }
      ],
      "wp:attachment": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/media?parent=122"
        }
      ],
      "wp:term": [
        {
          "taxonomy": "category",
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories?post=122"
        },
        {
          "taxonomy": "post_tag",
          "embeddable": true,
          "href": "https://demo.wp-api.org/wp-json/wp/v2/tags?post=122"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  }
]

スキーマ

投稿オブジェクトに定義されているフィールドの一覧です。

date
string型
datetime
サイトのタイムゾーンで、記事が公開された日時
属性:vieweditembed
date_gmt
string型
datetime
グリニッジ標準時で、記事が公開された日時
属性:viewedit
guid
object型
グローバルで、オブジェクトを一意に識別する
読み取り専用
属性:viewedit
id
int型
オブジェクトを一意に識別する
読み取り専用
属性:vieweditembed
link
string型
uri
オブジェクトのURL
読み取り専用
属性:vieweditembed
modified
string型
datetime
サイトのタイムゾーンで、記事が更新された日時
読み取り専用
属性:viewedit
modified_gmt
string型
datetime
グリニッジ標準時で、記事が更新された日時
属性:viewedit
slug
string型
英数字の識別子
属性:vieweditembed
status
string型
オブジェクトのステータス
属性:viewedit
例:publishfuturedraftpendingprivate
type
string型
オブジェクトのpostタイプ
読み取り専用
postのAPIの場合は、post
属性:vieweditembed
password
string型
内容と抜粋文へのアクセスを保護するためのパスワード
属性:edit
permalink_template
string型
オブジェクトのパーマリンクのテンプレート
読み取り専用
属性:edit
generated_slug
string型
オブジェクトのタイトルから自動で生成されたスラッグ
読み取り専用
属性:edit
title
object型
オブジェクトのタイトル
属性:vieweditembed
content
object型
オブジェクトの内容
属性:viewedit
author
int型
作者のユーザーID
属性:vieweditembed
excerpt
object型
オブジェクトの抜粋文
属性:vieweditembed
featured_media
int型
アイキャッチ画像のID
属性:vieweditembed
comment_status
string型
コメントが許可されているかどうか
属性:viewedit
例:openclosed
ping_status
string型
トラックバック・ピンバックを受け付けるかどうか
属性:viewedit
例:openclosed
format
string型
オブジェクトの形式
属性:viewedit
例:standardasidechatgallerylinkimagequotestatusvideoaudio
meta
object型
メタフィールド
属性:viewedit
sticky
boolean型
この投稿を先頭に固定表示するかどうか
属性:viewedit
template
string型
オブジェクトを表示するのに使用しているテーマファイル
属性:viewedit
categories
array型
オブジェクトが属しているカテゴリー・タクソノミー
属性:viewedit
tags
array型
オブジェクトが属しているタグ
属性: viewedit

リクエスト例

$ curl -X OPTIONS -i https://example.com/wp-json/wp/v2/posts
jQuery(function($){
    var baseUrl = 'https://demo.wp-api.org/wp-json/'

    $('.show-schema').on('click', function() {
        $.ajax({
            url: baseUrl + 'wp/v2/posts'
        })
        .done( (data) => {
            console.log(data)
        })
        .fail( (data) => {
            console.log(data)
        })
    })

})

投稿リスト

引数

contextリクエストが行われるスコープ。レスポンスに存在するフィールドを決定する。
デフォルト:view
例:viewembededit
page現在のページ数
デフォルト:1
per_page1ページの件数
デフォルト:10
search文字列にマッチする結果に絞り込む
afterISO8601に準拠した日付の後に公開された投稿に絞り込む
author特定の著者の投稿に絞り込む
author_exclude特定の著者の投稿を除外する
beforeISO8601に準拠した日付より前に公開された投稿に絞り込む
exclude特定のIDの投稿を除外する
include指定されたIDの投稿に絞り込む
offset指定された数から投稿を取得する
orderソート順を昇順か降順か決める
デフォルト:desc
例:ascdesc
orderbyソート順の基準を決める
デフォルト:date
例:authordateidincludemodifiedparentrelevancesluginclude_slugstitle
slugスラッグで絞り込む
statusステータスで絞り込む
デフォルト:publish
categoriesカテゴリーで絞り込む
categories_exclude特定のカテゴリーを除外する
tagsタグで絞り込む
tags_exclude特定のタグを除外する
sticky固定されている投稿に絞り込む

定義

GET /wp/v2/posts

リクエスト例

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

投稿の作成

引数

dateサイトのタイムゾーンで、記事が公開された日時
date_gmtグリニッジ標準時で、記事が公開された日時
slug英数字の識別子
status投稿のステータス
例:publishfuturedraftpendingprivate
password内容と抜粋文へのアクセスを保護するためのパスワード
titleタイトル
content内容
author著者のID
excerpt抜粋文
featured_mediaアイキャッチ画像のID
comment_statusコメントを受け付けるかどうか
ping_statusトラックバック・ピンバックを受け付けるかどうか
formatオブジェクトの形式
例:standardasidechatgallerylinkimagequotestatusvideoaudio
metaメタフィールド
stickyこの投稿を先頭に固定表示するかどうか
templateオブジェクトを表示するのに使用しているテーマファイル
categoriesオブジェクトが属しているカテゴリー・タクソノミー
tagsオブジェクトが属しているタグ

定義

POST /wp/v2/posts

IDを指定して投稿を取得

引数

id投稿ID
contextリクエストが行われるスコープ。レスポンスに存在するフィールドを決定する。
デフォルト:view
例:viewembededit
password投稿がパスワード保護されている場合は、パスワード

定義

GET /wp/v2/posts/<id>

リクエスト例

$ curl https://example.com/wp-json/wp/v2/posts/<id>

投稿の更新

引数

id投稿ID
dateサイトのタイムゾーンで、記事が公開された日時
date_gmtグリニッジ標準時で、記事が公開された日時
slug英数字の識別子
status投稿のステータス
例:publishfuturedraftpendingprivate
password内容と抜粋文へのアクセスを保護するためのパスワード
titleタイトル
content内容
author著者のID
excerpt抜粋文
featured_mediaアイキャッチ画像のID
comment_statusコメントを受け付けるかどうか
ping_statusトラックバック・ピンバックを受け付けるかどうか
formatオブジェクトの形式
例:standardasidechatgallerylinkimagequotestatusvideoaudio
metaメタフィールド
stickyこの投稿を先頭に固定表示するかどうか
templateオブジェクトを表示するのに使用しているテーマファイル
categoriesオブジェクトが属しているカテゴリー・タクソノミー
tagsオブジェクトが属しているタグ

定義

POST /wp/v2/posts/<id>

リクエスト例

$ curl -X POST https://example.com/wp-json/wp/v2/posts/<id> -d '{"title":"My New Title"}'

投稿の削除

引数

id投稿のID
forceゴミ箱に入れず完全に削除するかどうか

定義

DELETE /wp/v2/posts/<id>

リクエスト例

$ curl -X DELETE https://example.com/wp-json/wp/v2/posts/<id>