• I am wondering if there is a filter or a way to disable the caching for a specific endpoint.
    On my instance they are all on read more and no on writing but we have only one custom that do check and we want to avoid a cache for it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I see in the code this line:
    $allowed_endpoints = get_option( 'wp_rest_cache_allowed_endpoints', [] );
    But I am not sure about how to use or if there is something else.

    Plugin Author Acato

    (@acato)

    Yes you can! Use the hook wp_rest_cache/allowed_endpoints like this:

    /**
     * Unregister the /wp-json/wp/v2/comments endpoint so it will not be cached.
     */
    function wprc_unregister_wp_comments_endpoint( $allowed_endpoints ) {
        if ( isset( $allowed_endpoints[ 'wp/v2' ] ) && ( $key = array_search( 'comments', $allowed_endpoints[ 'wp/v2' ] ) ) !== false ) {
            unset( $allowed_endpoints[ 'wp/v2' ][ $key ] );
        }
        return $allowed_endpoints;
    }
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_unregister_wp_comments_endpoint', 100, 1);

    Is this what you were looking for?

    perfect thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to exclude endpoints’ is closed to new replies.