There must be some way one can disable W3TC object cache when accessing as admin. Perhaps it’s only a W3TC issue, but potentially ACF could have an option to disable its own cache if user is certain editor role, e.g. admin, author, editor, etc.
I have it set to 9999
!
In other news, I turned off the W3TC object cache and it seems to work.
I used W3TC’s object cache clearing, and in my debug logs I see that the fields get set into the cache, but when it comes to my custom acf/save_post
hook to read the saved custom field’s data the value is still false
. I’m still looking into it…
Hmmm, I feel like there should be some method to force retrieving an ACF value (like there is in the wp_cache_get
). I think this cache thing is really busting my code.
I do use W3TC and object caching, so it’s probable there’s some configuration there which is doing some interesting things, but I still find it interesting that there is a significant difference of behaviour when I’m on my local dev compared to the live production server, even though ACF and W3TC are configured the same and the theme functions.php
is exactly the same too.
I have a feeling it may be some kind of issue with the ACF cache.
In advanced-custom-fields-pro/api/api-value.php
for the acf_get_value
function I’ve dotted it with some error_log
function calls:
[code]
function acf_get_value( $post_id = 0, $field ) {
// vars
$cache_key = “get_value/post_id={$post_id}/name={$field[‘name’]}”;
error_log( $cache_key );
// return early if cache is found
if( acf_isset_cache($cache_key) ) {
error_log( ‘cache is set, retrieving from cache’ );
$cache_value = acf_get_cache($cache_key);
error_log( json_encode( $cache_value, JSON_PRETTY_PRINT ) );
return $cache_value;
}
// load value
$value = acf_get_metadata( $post_id, $field[‘name’] );
error_log( json_encode( $value, JSON_PRETTY_PRINT ) );
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize( $value );
error_log( json_encode( $value, JSON_PRETTY_PRINT ) );
// no value? try default_value
if( $value === null && isset($field[‘default_value’]) ) {
$value = $field[‘default_value’];
}
// filter for 3rd party customization
$value = apply_filters( “acf/load_value”, $value, $post_id, $field );
$value = apply_filters( “acf/load_value/type={$field[‘type’]}”, $value, $post_id, $field );
$value = apply_filters( “acf/load_value/name={$field[‘_name’]}”, $value, $post_id, $field );
$value = apply_filters( “acf/load_value/key={$field[‘key’]}”, $value, $post_id, $field );
error_log( json_encode( $value, JSON_PRETTY_PRINT ) );
// update cache
acf_set_cache($cache_key, $value);
// return
return $value;
}
[/code]
And then my debug error log output looks like this:
[code]
[22-Jan-2017 17:14:22 UTC] get_value/post_id=6180/name=products_selected
[22-Jan-2017 17:14:22 UTC] cache is set, retrieving from cache
[22-Jan-2017 17:14:22 UTC] false
[22-Jan-2017 17:14:22 UTC] action_save_post_selection
[22-Jan-2017 17:14:22 UTC] 6180
[22-Jan-2017 17:14:22 UTC] false
[22-Jan-2017 17:14:22 UTC] {
“field_5834bbcfd967e”: [
{
“field_etc”…
[/code]
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.