Most of the discussion about the WordPress rest API is about default path queries. In this sense, we think of it as a single API, such as the twitter API. However, the fact is that the WordPress rest API is not an API, but millions of APIs that can be highly customized, and can also be used as a tool to create APIs. Yes, these paths are provided with the default paths, but as needed, they are a compromise between thousands of sites, including many that have not yet been created. Just as WordPress is not an object of global wp_query, other APIs are not the default APIs. Keeping the default value is equivalent to using an existing word press project without creating a unique wp\u query object or overwriting the default query in pre\u get\u posts. Yes, but not all operations can be done through the default WordPress URL path. The
The same is true of rest APIs. In a recent interview with Ryan McCue, the co lead developer of the rest API, he talked about how version 2 of the project is divided into two parts: the default path and the infrastructure used to generate the restful API. The default path provides a good example of creating a unique path. The system for adding these paths and endpoints is excellent. In this article, we will show the basic content of the usage method. For example, we will show you how to create a custom path with two endpoints to display product information of e-commerce websites driven by easy digital (EDD). This example is based on the additional capabilities of the API built for my site. You can view the complete source code of GitHub or the running API. The
EDD provides its own restful API, but I want to expose specific custom fields used by my site. In my own implementation, I also integrated a second path called \
See add path my new favorite function. Rest API version 2 introduces a new function called register\u rest\u route(). This allows you to add paths and pass endpoint arrays to the rest API. In addition to providing a callback function for each endpoint to respond to the request, you can also define the required fields in the query, including the default, health and validation callbacks and separate permission callbacks. There are still evolving additional functions here. It is recommended that you read the classes of the default post path. Use the rest API to query the excellent resources of posts. The
Focus on callback, field parameters and permission verification. These three features show how the API architecture works. In addition, when you reach the callback, you will have all the fields you need and delete them, which is very useful. You can also see that the request has been approved. This architecture facilitates separation of concerns and code modularization. I can’t exaggerate how much I love it. When defining a routing custom route, use register\u rest\u route() in the function connected to \
This function allows 4 arguments. The first is the namespace of the path. All