We'll create fresh WordPress site with Advanced Custom Routes – Custom Endpoints for WP REST API installed. You have 20 minutes to test the plugin after that site we'll be deleted.
The REST API was a great additional to WordPress that made it easy to grab data through the default routes. The biggest issue with these default routes is it will either grab too much data or too little data and it didn’t make it easy to only grab the data you need. This plugin makes it possible to create custom routes where you can set to pull only the data you need/want. Even better you won’t even have to touch a line of code to make it work, everything will be configurable within the WordPress dashboard.
You can also filter your custom routes using query parameters that you add to the end of your custom route like so:
https://example.com/wp-json/custom-routes/v1/posts?id=1
In the example above it would only pull data for that custom route where the post’s ID was equal to 1. This can be used for multiple different query parameters:
You can also receive data for a single post at a custom route using either an ID or a Slug, like so:
https://example.com/wp-json/custom-routes/v1/posts/1
(This would grab the post with an ID of 1 at this custom route)
https://example.com/wp-json/custom-routes/v1/posts/hello-world
(This would grab the post with the slug of hello-world at this custom route)
Navigate to the ‘Add New’ in the plugins dashboard
Search for ‘Advanced Custom Routes’
Click ‘Install Now’
Activate the plugin on the Plugin dashboard
Navigate to the ‘Add New’ in the plugins dashboard
Navigate to the ‘Upload’ area
Select advanced-custom-routes.zip from your computer
Click ‘Install Now’
Activate the plugin in the Plugin dashboard
Download advanced-custom-routes.zip
Extract the advanced-custom-routes directory to your computer
Upload the advanced-custom-routes directory to the /wp-content/plugins/ directory
Activate the plugin in the Plugin dashboard