Home › Forums › General Issues › Issues with get_field on save_post hook › Reply To: Issues with get_field on save_post hook
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.