Dynamic Routes doesn’t caching
-
Thats my code, the route is created by slug, example:
/wp-json/api/courses, but not caching, What can i do to fix this?<?php function get_page_content($request) { return include_once "endpoints/".explode('?', $request['slug'])[0].".php"; } function courses_cache( $allowed_endpoints ) { if ( ! isset( $allowed_endpoints[ 'api' ] ) || ! in_array( 'courses', $allowed_endpoints[ 'api' ] ) ) { $allowed_endpoints[ 'api' ][] = 'courses'; } return $allowed_endpoints; } add_filter( 'wp_rest_cache/allowed_endpoints', 'courses_cache', 10, 1); function get_page_info() { register_rest_route('api', '/(?P<slug>\S+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'get_page_content', ), )); } add_action('rest_api_init', 'get_page_info');
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Dynamic Routes doesn’t caching’ is closed to new replies.