Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sync ACF fields across sites on WP multisite

I've been searching for a way to sync ACF fields across sites on a WordPress multi-site. There are 5 sites with individual content but they all use the same ACF fields. I'd rather avoid having to manually create and add these new fields on each site.

Is there a workaround?

Using WP 4.8 and ACF Pro 5.5.1.4

like image 378
Staffan Estberg Avatar asked Jul 18 '17 06:07

Staffan Estberg


People also ask

Does ACF work on multisite?

Yes, ACF Extended is compatible with WP multisite installations. Note that this plugin is an addon on top of ACF Pro, so of course any Field Groups created using ACF will be working just like before, including with the native ACF local Json feature.

How do you sync ACF fields?

To enable the Json Sync, check the “Json Sync” setting in the targeted field group. Note: By default, if a Json folder has been declared within the theme or the code, ACF Extended will automatically check the “Json Sync” setting on all newly created field groups, in order to stick to the native ACF behavior.

Where does ACF store custom fields?

In ACF world, a Field Group is a collection of custom fields that will be displayed together on a WP-Admin editing screen. Behind the scenes, a Field Group is a type of custom post, which means they can be found in the Posts table of your WordPress database.


2 Answers

Since you are using ACF Pro you could make use of the "Export/Import" feature.

  1. Network Activate Advanced Custom Fields
  2. Create Field Groups on the Main Site through the Custom Fields Menu.
  3. Use Custom Fields –> Export, select all field groups, Export to PHP
  4. Paste the PHP into your (child) theme’s functions.php
  5. Go back and trash the fields from the main site so there aren’t duplicates.

You now have ACF fields available network-wide.

like image 192
Benjamin Löffel Avatar answered Oct 09 '22 02:10

Benjamin Löffel


I was thinking about this same thing couple of times before and came to conclusion that easiest thing would be to create a github repo with set of acf-field-name.php files and then bring those repos as submodules to each of your projects. If you place this php files in acf folder within your theme folder and use function within functions.php like this

    function getAcfFileNames()
    {
        return array(
            'acf-one',
            'acf-two',
            'acf-three',
        );
    }

    function add_php_acf_field_groups()
    {
        $fileNames = getAcfFileNames();
        foreach ($fileNames as $fileName) {
            include_once 'acf/' . $fileName . '.php';
        }
    }

    ;
    add_action('acf/init', 'add_php_acf_field_groups');

That should work just fine. And if you want to edit those acf.php files within project you can use -> https://github.com/BeAPI/ACF-PHP-Recovery to recover php file locally and update it. After that just export the file and commit it to your ACF repo.

Other then that unfortunately I haven't found better solution.

like image 2
Tom Avatar answered Oct 09 '22 02:10

Tom