Support

Account

Home Forums Bug Reports Multi-Sites switch_to_blog bug

Solved

Multi-Sites switch_to_blog bug

  • Regarding this solved topic:

    http://support.advancedcustomfields.com/forums/topic/multisite-switch_to_blog-options-issue/

    I see that re-creating the fields using the plugin’s interface solved this problem for Full Circle Design. However, I have a Multi-Sites setup which has one main site and 25 satellite sites (and growing) which all will feed certain data into the main site. The satellite sites need to be setup quickly and the same way every time, so I need the fields to be created in the functions.php file. However I still need to access the field values from the main site, using switch_to_blog and a custom WP_Query.

    Elliot, do have any suggestions for how I can access the custom field data in this situation?

  • Hi @jzsouthern

    Sorry, I don’t understand what the issue is here. If your fields are registered via PHP and use the same field_key’s, there should be no issue with loading data with the switch_to_blog function…

    Thanks
    E

  • It just doesn’t work. The data doesn’t load at all for fields created in the functions.php file after I’ve switched blogs. (Fields created in Admin interface work just fine, even after switch_to_blog).

    I had to use the old get_post_custom and get_option functions to get data to load after a switch_to_blog call, which is fine, but this is pretty unexpected behavior for the plugin that could potentially break multi-sites installations that rely on your plugin. Seems like it should work whether the field is created via PHP in the theme or through the plugin interface in the Admin.

    Thanks for the awesome plugin, and I hope this helps clarify.

  • Hi @jzsouthern

    potentially, when you switch blogs, the fields are not registered on the new blog. Therefore, ACF can’t load in the data.

    Could this be the issue?

    I would suggest that you do use the native and basic postmeta functions for this as it removes the need of knowing the $field.

    Thanks
    E

  • Hey @elliot ,

    Any chance on fix (or workaround) for this one.

    I’m currently using:

    get_post_meta($page_id, 'acf_field_name', true);

    but things get crazy with nested repeaters.

    I can provide exact code which doesn’t work when acf fields are loaded in the functions file.

    Thanks,
    Peter

  • I have run into this issue as well. Have not tried the get_post_meta (this gets messy with repeaters!!!).

    I posted on stack overflow and had another developer help me troubleshoot.

    http://wordpress.stackexchange.com/questions/180424/multisite-wp-query-switch-to-blog-issue

    I’m going to try to reproduce this on a fresh multisite install with a simplified test case.

  • Found this thread and after reading it I went and looked over a complex multisite that I am just about finished building.

    I thought that my input might be useful for someone.

    I am not seeing any problems with acf and switch_to_blog. Granted, I have a habit of using get_post_meta and get_option instead of acf field functions, but there are places that I still use them and I’m not seeing any problem.

    I think that the main difference, and this is only a guess, is that I did not export my field groups and then put them into the functions.php file. I wanted to put the same fields on every site, but I wanted the fields to remain editable. I also did not want anyone that had the ability to work on any of the sites to be able to edit the field groups. So what I did was use the local acf JSON feature of ACF5.

    What I have is one theme set up for the main site that is not available for the other sites, to do this you network activate the them then activate in on the main site and then network deactivate it. I then created a plugin that switches to the main site and loads all of the field groups for the main whatever site is being loaded. I honestly don’t know why this would be different that adding code to functions.php, but since it’s the only difference? Or maybe it has something to do with being in a plugin?

    Anyway, if anyone is interested I put a copy of this plugin up on GitHub

    https://github.com/Hube2/acf-field-group-autoloader

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

The topic ‘Multi-Sites switch_to_blog bug’ is closed to new replies.