Hi @mastababa
Thank you for using our plugin!
Are you using a custom endpoint for this post type or de default WordPress endpoint (i.e. /wp-json/wp/v2/<post-type-slug>)?
In the last situation the cache should automatically clear, unless you are using something different than the default WP function (like wp_update_post or update_post_meta ) for updating the post. Or if you are filtering the output of the endpoint using the _fields parameter, in that case you should include the fields id and type (or id and taxonomy in case of a taxonomy-endpoint). These fields are needed for our plugin to detect the correct object type of the items in the endpoint.
In case you are using a custom endpoint, you probably have to help our plugin detect the items inside the endpoint (see our FAQ)
Thanks.
Indeed, when I need the cache to clear is when I’m using a custom Ajax call, not a default endpoint or function.
I did have a look at your FAQ, but I could not find something that matched my use-case.
My custom Ajax calls call ACF’s update_field() function. So, are you implying that if I follow my call to update_field() with something like the below, the cache is automatically cleared?
$my_post = array(
'ID' => $post_id,
);
wp_update_post( $my_post );
Or do I actually have to update something? So, I perhaps need to do this:
$my_post = array(
'ID' => $post_id,
'post_title' => $temp_title
);
wp_update_post( $my_post );
$my_post = array(
'ID' => $post_id,
'post_title' => $actual_title
);
wp_update_post( $my_post );
Hi,
I wouldn’t do a wp_update_post if there is no need to actually update it. Instead you can tell our plugin to clear the related caches:
\WP_REST_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_related_caches( $post_id, $post_type );
Thanks. That’s indeed the kind of thing I was looking for.
However, I’m not getting quite the result I am expecting.
In fact, I now discover that, even after deleting all REST cache, I’m still handling responses that seem to be cached in the browser, as no new cache is generated after requesting that for which cache was just cleared. :/
@mastababa Since there is no new cache generated it seems your call isn’t coming through to WordPress. Unfortunately htere isn’t much our plugin can do in this case.
Yes, that’s indeed what I’m seeing. With the plugin turned on, the REST responses seem to be cached in the browser. With the plugin turned off, they are not. I had a similar problem earlier, and tried to ameliorate this through CloudFlare, but I remember that I could not get that to work.