Support

Account

Home Forums Backend Issues (wp-admin) Local JSON fallback?

Solved

Local JSON fallback?

  • I’ve consulted the documentation on Local JSON here:
    https://www.advancedcustomfields.com/resources/local-json/

    As I researched, it appears that the JSON file only gets loaded if there isn’t an entry in the wp_posts table for that field/field group. Is it possible to force ACF to ONLY pull from the JSON? Or is there a way to make ACF update based on the JSON file?

    In terms of keeping fields synchronized across installations, this would be the preferred method for my group.

    Thanks! Love the plugin!

  • ACF loads the JSON file first everywhere but when editing a field group. When editing a field group ACF pulls from the database only. In order to sync the field group you need to go into the list of field groups and sync them manually.

    Depending on what you’re looking to do it might be possible to force the syncing, look at the field group and the date is was modified and then call the ACF function to import the group, which is the function that does the synchronization. I can’t give you specifics, because I don’t know them.

  • Ok, that’s great information, thanks.

    The thing I’d like is, at minimum, to be able to create and define ACF field groups in a parent theme. If there are no database entries for those field groups, then ACF should continue to use the JSON list. Here’s my code for selecting saving sites:

    
    // Integrating Advanced Custom Fields:
    add_filter( 'acf/settings/save_json', function() {
        return get_stylesheet_directory() . '/Library/Acf-Json';
    } );
    add_filter( 'acf/settings/load_json', function( $paths ) {
        unset( $paths[0] );
        $paths[] = get_template_directory() . '/Library/Acf-Json';
        $paths[] = get_stylesheet_directory() . '/Library/Acf-Json';
        return $paths;
    } );
    

    Here’s what I’m experiencing:

    1. Activated the child theme
    2. Checked the CPTs, fields are present and accounted for.
    3. For consistency’s sake, activated the parent theme and looked.
    4. CPTs are showing the custom fields just fine.
    5. Switched back to the child theme.
    6. Check the Custom Fields index page. There are NO field groups listed, whatsoever.
    7. Switch back to the parent theme and look.
    8. Custom Fields shows no field groups.

    If you could point me in the direction of the code where all this magic happens, I’d be able to suss out the way it works myself. But I’m confused, because it seems like there must be a field, perhaps in thw wp_options table, that says what editable fields exist? Otherwise, where did the fields go?

    Thanks so much for your assistance!!

  • I think you may be running into issues because you are working on parent/child themes on the same site, same db tables.

    When I do this I do it on a multisite setup. One site is set up to use the parent theme and this is the only place I edit field groups in ACF. A second site is set up to use the child theme and I do not edit field groups on this site. If I do, then they only apply to the child theme and do not effect the parent theme. You could also do this on multiple sites.

  • Thanks for your help! I’ll need to look into that.

  • Ok. I’ve had a look at the actual code and based on that, I’ve opted to unhook the current ACF functions and replaced them with my own. So with slight modification, this is the result:

    
    // Integrating Advanced Custom Fields:
    remove_filter( 'acf/settings/save_json', 'settings_save_json' );
    add_filter( 'acf/settings/save_json', function() {
        return get_stylesheet_directory() . '/Library/Acf-Json';
    } );
    remove_filter( 'acf/settings/load_json', 'settings_load_json' );
    add_filter( 'acf/settings/load_json', function( $paths ) {
        array_push(
            $paths,
            get_stylesheet_directory() . '/Library/Acf-Json',
            get_template_directory() . '/Library/Acf-Json'
        );
        return $paths;
    } );
    

    This seems to be the most effective way of getting ACF settings to use the parent theme as a fallback.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Local JSON fallback?’ is closed to new replies.