How can I cache WordPress Rest API Response

You should create a new instance from WP_REST_Response to set the Cache-Control value. <?php register_rest_route(‘wp/v2’, ‘/your_endpoint’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘function_callback’, )); function function_callback($data) { $response = array( 1,2,3,4,5,6,7,8 ); $result = new WP_REST_Response($response, 200); // Set headers. $result->set_headers(array(‘Cache-Control’ => ‘max-age=3600’)); return $result; } Click here to get more info about directives.

Widget – Store and update data

You probably want to look at using WordPress Transients as they can handle both the data and the timestamp/expiration. You can also check out The Deal with WordPress Transients by CSS Tricks which has some good info as well.

Most performant way of fetching remote API data?

The most performant way of fetching remote API data is not fetching it at all. Thus, use Transients API or WP Object Cache to save your computed results for future use and avoid calling external API (and further computations) on every subsequent request. Additionally, fetching, invalidating and regeneration of this data can be done in … Read more

WP Rest API not working

First you’ve to Check if the WordPress REST API is enabled or not The best way to check is to visit this URL: https://yoursite.com/wp-json. If you see some JSON response, REST API is enabled. If it’s showing some error page or returns to home page, REST API is not enabled. Then we’ve to enable it … Read more

Post body not working with wp_remote_post()

You’re setting the Content-Type header to application/json and wp_remote_post() doesn’t intelligently JSON-encode the request data (the body array), so you should manually do it. So for example: ‘body’ => json_encode( array( ‘Username’ => ‘myusername’, ‘Password’ => ‘mypassword’ ) )

Get all tags not just first 10 with wp api 2.0

If we look at the WP_REST_Controller::get_collection_params() method, we can see the minimum is 1 and the maximum is 100: ‘per_page’ => array( ‘description’ => __( ‘Maximum number of items to be returned in result set.’ ), ‘type’ => ‘integer’, ‘default’ => 10, ‘minimum’ => 1, ‘maximum’ => 100, ‘sanitize_callback’ => ‘absint’, ‘validate_callback’ => ‘rest_validate_request_arg’, ), … Read more