ACF changes not caching
-
Hi! I have some custom post types coupled with the Advanced Custom Fields plugin. I enabled WP Rest Cache, but it doesn’t flush when editing any of the custom fields present in my custom post type. Anything I can do to fix this?
Thank you very much!
-
Thank you for using our plugin!
What plugin are you using to add the ACF fields to the REST API? Because out-of-the-box ACF fields aren’t added to the REST API output.
However it should work correctly. I just did a test without any extra plugin (so only ACF and WP REST Cache enabled) and the caches were flushed when I changed the value of an ACF custom field.
We use ACF all the time together with the ACF to REST API plugin (https://ww.wp.xz.cn/plugins/acf-to-rest-api/) and haven’t had any issues with the cache not being flushed when editing a custom field value.This is my list of currently installed plugins: https://pasteboard.co/JLKz4qi.png
So yes, I am using “ACF to REST API” plugin. It also happens with the custom post title for example. I change something, save, and the API response is the same as before. When I deactivate WP Rest Cache, the response updates.
Also, these are some of the endpoints that are being cached, if it helps for anything: https://pasteboard.co/JLKEtO0.png
Is there any setting I could be missing? Thank you for the quick response!
-
This reply was modified 5 years, 3 months ago by
Bruno De Angelis.
-
This reply was modified 5 years, 3 months ago by
Bruno De Angelis.
Am I correct in assuming these endpoints are custom endpoints which you have enabled caching for? And are these also the endpoints with flush issue? Because if that is the case it might not have anything to do with ACF, but any field you edit might cause the cache not to be flushed.
What does theObject Typecolumn for those endpoints say? If it saysunknownthan that is the problem. Our plugin cannot determine the object type of the item(s) in the endpoint and therefore it does not know when to flush it. See our FAQ to help our plugin determine the correct object type.Hi @rockfire,
the problem is exactly what you mentioned. It says “unknown” in the Object Type: https://pasteboard.co/JMzyx5V.png
Adding the script in functions.php doesn’t seem to be fixing the problem. I assume I must add some code, but I’m not exactly sure how to detect the object type automatically.
Thank you!
Without knowing the contents of the endpoints and what post types you are using, it is hard for me to write some code for you. But I will try to help you:
Am I right in assuming that
propiedadandempendimientoare custom post types? If so our plugin should be able to determine there post types (= object types) automatically. However if theidand/or thetypeisn’t presentin the REST result (because you might have filtered it out) than our plugin can not determine the correct object type. Easiest solution would be to make sureidandtypeare present.If for some reason you can not add those you could use the filter as described in our FAQ, something like this should work:
function wprc_determine_object_type( $object_type, $cache_key, $data, $uri ) { if ( $object_type !== 'unknown' ) { return $object_type; } if ( false !== strpos( $uri, 'propiedad') ) { return 'propiedad'; } if ( false !== strpos( $uri, 'empendimiento') ) { return 'empendimiento'; } return $object_type; } add_filter( 'wp_rest_cache/determine_object_type', 'wprc_determine_object_type', 10, 4 );Please delete all
unknowncaches after applying this code.Hi @rockfire
I was able to also put the
typefield in the response, since I’m changing it a bit infunctions.php. Now the plugin flushes the cache appropiately as soon as I change any field. However, something odd has happened. When I append the_envelope=1query param to the request (I use it for getting the amount of posts returned), the response simply crashes: https://pasteboard.co/JMGWuXb.pngAny other query param seems to be working: https://pasteboard.co/JMGWYZh.png
Any idea why this could be happening? In any case, your help has been amazing! Thank you very much.
We don’t use the
_envelope=1query param (we get the amount of posts from the response headers), but I just did a test and it doesn’t crash. Could you have a look in your error logs to see what the exact error is?Edit: but now I do notice that the cache with the
_envelopeparameter doesn’t detect the object type correctly. I will add this to our todo-list, because it should be able to detect it automatically.-
This reply was modified 5 years, 3 months ago by
Richard Korthuis.
I Suggest that added
update_postmetaaction for clear post cache.
when we changed ACF or Post meta field in REST API not WordPress admin area.
it not regenerate post meta cache. -
This reply was modified 5 years, 3 months ago by
The topic ‘ACF changes not caching’ is closed to new replies.