Support

Account

Home Forums Backend Issues (wp-admin) Restricting acf_add_local_field_group to specific blogs in network

Solved

Restricting acf_add_local_field_group to specific blogs in network

  • Hi – Great product.

    I have a parent theme with its own custom fields for a top level organization site, and a child theme with its own custom fields applied across a Multisite Network.

    I’m moving all ACF declarations from the admin UI to functions.php with the PHP export utilizing acf_add_local_field_group. But now these fields are being applied to the child sites, too.

    What would be the best way to migrate these fields to functions.php without them interfering with each other? Can they be declared for specific blog IDs only? Or should I give up on the parent theme idea?

  • Hi @spacedragon

    You could simply wrap the functions in an if statement checking the current blog id 🙂

    
    <?php if( get_current_blog_id() == 1 ){
    	echo 'This would only show on the first blog (the primary)';
    } ?>
    
  • I’ve been considering that, but concerned it would be resource intensive on a 300+ site network. The solution works fine in the development environment.

  • No problem. It doesn’t matter how many sites you have in the network since it will just query out that single ID from the wp_sites table (I believe).

    get_current_blog_id() does not make an extensive heavy query regardless of size of your network. So it should be fine!

    If you’re still worried you can use a tool like Query monitor to see exactly how it affects the sites
    https://sv.wordpress.org/plugins/query-monitor/

  • Thank you, Jonathan! I appreciate the advice and resource link.

  • You’re welcome! Best of luck with your network!

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

The topic ‘Restricting acf_add_local_field_group to specific blogs in network’ is closed to new replies.