Support

Account

Home Forums General Issues get_field returning null after update

Solved

get_field returning null after update

  • Oh and I forgot to say but the fields inside the JSON were made with ACF, so the argument “get_field for fields created with ACF work” is false, because if it was created by ACF but exported in JSON (which is the way local json ACF feature works), the update will now ignore these fields !!

    Please fix this, it’s just unacceptable.

  • @benjamin74 i have your same situation (using json for options). I have problems with fields not created by ACF (json or not) and i’m fixing them using get_post_meta but i HAVE NOT problems using fields generated by json. How do you call json? Perphaps you call get_field before jsons are loaded?

  • It has always worked for me. Of course I’m loading local json ACF fields before any call.

    But I’m using ONLY json, i.e. I do NOT SYNC from json.

    Here is the code I’m using:

    
    // 1.9 Now support LOCAL ACF JSON FIELD DEFINITION
    //https://www.advancedcustomfields.com/resources/local-json/
    //https://awesomeacf.com/how-to-avoid-conflicts-when-using-the-acf-local-json-feature/
    // ON PRODUCTION, DON'T SYNC AND NEVER EDIT THE FIELD SETTINGS IN ACF
    add_filter('acf/settings/save_json', 'bja_wf_acf_json_save_point');
    function ben_wf_acf_json_save_point( $path ) {
    	// update path
    	$path = BENWF_PLUGIN_PATH . 'acf-config';
    	// return
    	return $path;
    }
    
    add_filter('acf/settings/load_json', 'ben_wf_acf_json_load_point');
    function ben_wf_acf_json_load_point( $paths ) {
    	// remove original path (optional)
    	unset($paths[0]);
    	// append path
    	$paths[] = BENWF_PLUGIN_PATH . 'acf-config';
    	// return
    	return $paths;
    }
    

    e.g. like as described in this article here:
    https://www.awesomeacf.com/how-to-avoid-conflicts-when-using-the-acf-local-json-feature/
    see chapter “The preventative workflow” -> I’m using option 1 described in that paragraph.

  • Also (maybe it makes a difference), my custom fields are for a site Option Page, not custom post fields…

    https://www.advancedcustomfields.com/resources/options-page/

    so I’m calling their values this way:

    $variable = get_field(‘field_name’, ‘option’);

  • @benjamin74

    it’s most like my code just some differences:

    1) i set third parameter as 1 (small difference i think)

    add_filter('acf/settings/load_json', 'red_template_json_load_point', 1);
    add_filter('acf/settings/save_json', 'red_template_json_save_point', 1);
    
    function red_template_json_load_point( $paths ) { 
        // remove original path (optional)
        unset($paths[0]);
        // append path
        $paths[] = get_template_directory() . '/includes/acf_json';
        // return
        return $paths;
    }
    
    function red_template_json_save_point( $path ) { 
        // update path
        $path = get_template_directory() . '/includes/acf_json';
        // return
        return $path;
    }

    2) i use “options” and not “option”. Perhaps this?

    $red_tmp_font_h1_font = get_field("h1_red_tmp_font_h1_font","options");

  • The docs say it’s singular “option”:

    https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/

    I’ve tried adding 1 as the third parameter but it didn’t solve anything.

    Honestly when I see the remarks by the Dev, it’s obvious that they screw up with this update.

  • @dany0 are you sure that you didn’t sync your fields ?

  • @benjamin74

    i wrote “you are right, without sync i have same problem”, but i tested code in child functions so before json loaded…. tested on page.php is ok

  • While get_field() returns the right content on post_type pages, it returns null on taxonomies, even though these fields have been created from the ACF editor. Can anybody recommend how to use get_field() on taxonomies on 5.11?

    I consider that this was not a minor update and therefore should have been notified as such. The issue happened updating from 5.10 to 5.11 and nobody expected it could generate issues. For example all my SEO elements, such as SEO title or meta descriptions are controlled by ACF and therefore my sites could have been seriously affected If I would not have seen it right after updating.

  • @retroriff just tried and it works for me. How do you call field on taxonomy?

  • @dany0 get_field('my_field', $taxonomy . '_' . $term_id)

  • do you still see field on the taxonomy in the backend?

  • Yes, this works: get_term_meta($term_id, 'my_field', true)

  • No news from support yet… in the meantime I’ve discovered more details about that bug (which could explain why @dany0 didn’t always get the same results as I did)

    So with a custom Settings Option page loaded only from a JSON file (NOT SYNC’ed) and for example an option called “goshow_blabla_percent”

    – From a sidebar PHP widget, this WORKS :

    
    <?php
    
    echo "get_field value is:" . get_field('goshow_blabla_percent', 'option') . "END";
    
    ?>
    

    But from my plugin, using this :

    
    add_filter('acf/settings/save_json', 'gowf_acf_json_save_point');
    function gowf_acf_json_save_point( $path ) {
    // update path
    $path = BJAWF_PLUGIN_PATH . 'acf-config';
    // return
    return $path;
    }
    
    add_filter('acf/settings/load_json', 'gowf_acf_json_load_point');
    function gowf_acf_json_load_point( $paths ) {
    // remove original path (optional)
    unset($paths[0]);
    // append path
    $paths[] = BJAWF_PLUGIN_PATH . 'acf-config';
    // return
    return $paths;
    }
    
    $value = get_field('goshow_blabla_percent', 'option');
    

    => Will set $value to NULL…

    it has been working for years but it doesn’t work with 5.11 !!

  • @benjamin74

    You have your JSON load point set as

    
    add_filter('acf/settings/load_json', 'ben_wf_acf_json_load_point');
    function ben_wf_acf_json_load_point( $paths ) {
    	// remove original path (optional)
    	unset($paths[0]);
    	// append path
    	$paths[] = BENWF_PLUGIN_PATH . 'acf-config';
    	// return
    	return $paths;
    }
    

    by using unset($paths[0]); only the json files from your plugin will be loaded. If you want to add an addional load point then you need to remove that.

    Also by changing the save point you are changing the save point for every field group to be saved into your plugin folder.

  • The docs say it’s singular “option”:

    ACF corrects for “options” vs “option”, either should work.

  • Yes John it’s on purpose that I use unset($paths[0]);

    I solely rely on JSON loaded from my plugin.

    It’s never been an issue.

  • I am also have this issue. It looks like it’s just the options that are no longer loading properly with get_field() when loaded via json file. The rest of my fields seem to be working with posts, pages, etc. They are loading in the options page, just not in my theme/plugins with get_field(). If I sync the field it works. I don’t like to sync the fields in production though because I pass acf-json/ through version control.

    Let me know if there is any way I can help!

  • Nope we have to wait for the Dev to fix this. I sent them extensive videos of the setup that doesn’t work.

    It’s definitely get_field() from json and inside a plugin that doesn’t work (it works for example if you call get_field() from a PHP widget for example).

    I too MUST keep json field definition for version control and to be sure that the definitions of fields are the same across multiple sites…

  • I am not exactly sure what the problem is with some people having issues with fields created in JSON files for options pages.

    I just tested this on a site with one of my plugins. The plugin creates an options page and the field group on that options page is loaded from an acf-json folder in the plugin. The field group is not synced into the DB. Everything is working as expected, values are correctly returned using get_field().

    There must be some other reason that it’s not working other than options page, json file or syncing.

  • If I put the call to get_field() in the ‘plugins_loaded’ action, I get the correct value. If I take it out of that action, I get an empty string.

  • @cbrady23 if the get_field() call is not in a “plugins_loaded” action, when is it called?

    By when I specifically mean is it called before or after the acf/init action is fired.

    Basically, no acf function should be called before the acf/init action fires. This happens on the WP “init” action at a priority of 5. Calling any ACF function before this time will cause unexpected results. Even the “plugins_loaded” function is really too soon. In some cases calling an ACF function too early causes what I call premature initialization. What I mean by that is that ACF looks to see if it has been initialized by looking to see if the acf/init function has been fired [did_action()] and if the action has not been done ACF calls its initialization routine and ACF will not initialize before the ‘plugins_loaded’ hook

    
    function init() {
    
      // Bail early if called directly from functions.php or plugin file.
      if ( ! did_action( 'plugins_loaded' ) ) {
        return;
      }
      
      // This function may be called directly from template functions. Bail early if already did this.
      if ( acf_did( 'init' ) ) {
        return;
      }
      
      ...
    
Viewing 25 posts - 26 through 50 (of 88 total)

You must be logged in to reply to this topic.