Custom endpoint – Only get one entry
-
Hi! Great plugin! Great job you’ve done!
I need a bit of help in using it with custom endpoints though..
Can I use custom endpoints like /products/(?P<id>[\d]+) ? How do I do that correctly?
Here’s how I register my rest route:function cc_register_rest_routes() { register_rest_route( 'cc-rest/v1', '/products/(?P<id>[\d]+)', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'cc_rest_get_product', ) ); }Now when I use this:
function my_add_products_endpoints_to_cache( $allowed_endpoints ) { if ( ! isset( $allowed_endpoints[ 'cc-rest/v1' ] ) || ! in_array( 'products', $allowed_endpoints[ 'cc-rest/v1' ] ) ) { $allowed_endpoints[ 'cc-rest/v1' ][] = 'products'; } return $allowed_endpoints; } add_filter( 'wp_rest_cache/allowed_endpoints', 'my_add_products_endpoints_to_cache', 10, 1);I only get the first record cached, eg.
/cc-rest/v1/products/176.
All other requests ‘…/175’ , ‘…/181’ etc. are not.
And even if I delete the only cache record, the new ones don’t appear (or the old one reappear btw).
Thanks.P.S. So far I’ve been trying this on a local server only so can’t provide a link
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Custom endpoint – Only get one entry’ is closed to new replies.