Sync ACF fields across sites on WP multisite
Asked Answered
I

4

7

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

Iatry answered 18/7, 2017 at 6:55 Comment(1)
have you tried? github.com/tmconnect/acf-relationship-multisiteIsmaelisman
F
15

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.

Frescobaldi answered 25/7, 2017 at 18:1 Comment(0)
M
2

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.

Monmouthshire answered 20/7, 2017 at 14:44 Comment(0)
S
1

There is a great Gist by Jesse Pearson which automatically syncs all acf-json files when the admin logs in:

https://gist.github.com/jessepearson/a537b2f78556cd705947

In the comments to the gist you can also find several improvements on the code, watch out for those!

Saved me a ton of time.

Stereogram answered 8/5, 2019 at 10:52 Comment(0)
E
0

You can sync the fields no problem as long as you are attaching them to template names and not specific pages or posts.

https://www.advancedcustomfields.com/resources/synchronized-json/

Just make a quick change to your function.php file.

https://www.advancedcustomfields.com/resources/local-json/

I have used the exported PHP code method when I am done working locally and want to update a production theme.

Expertise answered 1/3, 2019 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.