• Resolved sharulhafiz

    (@sharulhafiz)


    I tried to register custom endpoint, but it doesn’t seem to work, nothing appears Endpoint API Caches. Here is my code:

    add_action( 'rest_api_init', function () {
      register_rest_route( 'utmsmart', '/(?P<slug>[a-zA-Z0-9-]+)', array(
        'methods' => 'GET',
        'callback' => 'beforeyouarrive_query',
      ) );
    } );
    
    /**
     * Register the /wp-json/utmsmart/(?P<slug>[a-zA-Z0-9-]+) endpoint so it will be cached.
     * 
     */
    function wprc_add_acf_posts_endpoint( $allowed_endpoints ) {
        if ( ! isset( $allowed_endpoints[ 'utmsmart' ] ) || ! in_array( '/(?P<slug>[a-zA-Z0-9-]+)', $allowed_endpoints[ 'utmsmart' ] ) ) {
            $allowed_endpoints[ 'utmsmart' ][] = '/(?P<slug>[a-zA-Z0-9-]+)';
        }
        return $allowed_endpoints;
    }
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_acf_posts_endpoint', 10, 1);
    
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Endpoint Help’ is closed to new replies.