📜  wordpress rest api tags (1)

📅  最后修改于: 2023-12-03 14:48:32.172000             🧑  作者: Mango

WordPress REST API Tags

WordPress REST API allows developers to retrieve and manipulate WordPress data using standard HTTP requests. Among the many benefits of utilizing REST API in WordPress is the ability to retrieve all types of data, including tags. When using WordPress REST API, tags can be retrieved, updated, and deleted by sending GET, PUT, and DELETE requests respectively.

Retrieving Tags

To retrieve a list of all tags available on your WordPress site using REST API, send a GET request to the following endpoint:

/wp-json/wp/v2/tags

Sending a GET request to this endpoint will return an array of all tags, each tag represented by a JSON object with its respective properties, such as ID, name, description, and slug.

Example:

GET /wp-json/wp/v2/tags HTTP/1.1 Host: www.yoursite.com

Adding a New Tag

To add a new tag to your WordPress site using REST API, send a POST request to the following endpoint:

/wp-json/wp/v2/tags

The POST request must include the following JSON object representing the new tag to be added, including the name and slug properties.

Example:

POST /wp-json/wp/v2/tags HTTP/1.1 Host: www.yoursite.com Content-Type: application/json

{ "name": "New Tag", "slug": "new-tag" }

Updating a Tag

To update an existing tag on your WordPress site using REST API, send a PUT request to the following endpoint:

/wp-json/wp/v2/tags/{tag_id}

The PUT request must include the following JSON object representing the updated tag, including the name and slug properties.

Example:
PUT /wp-json/wp/v2/tags/5 HTTP/1.1
Host: www.yoursite.com
Content-Type: application/json

{
  "name": "Updated Tag",
  "slug": "updated-tag"
}
Deleting a Tag

To delete an existing tag on your WordPress site using REST API, send a DELETE request to the following endpoint:

/wp-json/wp/v2/tags/{tag_id}
Example:
DELETE /wp-json/wp/v2/tags/5 HTTP/1.1
Host: www.yoursite.com
Conclusion

WordPress REST API provides a powerful and flexible way for developers to interact with WordPress site data, including tags. With REST API, developers can retrieve, add, update, and delete tags using standard HTTP requests, making WordPress development more efficient and streamlined.