Home › Forums › General Issues › update_field and switch_to_blog
I’m trying to use a form on one site to save some ACF values to a post on another site from a front-end form (all in the same multi-sites installation of course). For some reason I can’t seem to get the values to save. Can I use update_field after I’ve called switch_to_blog? Or is it too late at that point?
Here’s the code I’m attempting to use. It’s all wrapped in a ‘gform_after_submission’ call (from Gravity Forms). I’ve confirmed that the GF hook is working properly, and that all the values are getting passed in the Entry object properly…
//Switch to the school's blog
$school_blog = $entry[2];
switch_to_blog($school_blog);
$post_id = $entry[1];
if (update_field( 'field_5215741f54e1f', $entry[3], $post_id )) { //Win or Loss
update_field( 'field_5215744854e20', $entry[4], $post_id ); //Our Score
update_field( 'field_5215746754e21', $entry[5], $post_id ); //Opponent Score
} else {
die('Sorry, but the score couldn\'t be updated. Please try again later.');
}
// Restore Original Post Data
restore_current_blog();
Just an update – I tried to do this without any Gravity Forms code at all to see if that might be the problem – I just created a simple form in one page template and submitted it to another page, with a template to process the form. Still no dice. I’m thinking this is a conflict with switch_to_blog() and update_field()
$channel_blog = $_POST['channel_blog'];
$event_id = $_POST['event_id'];
$win_loss = $_POST['win_loss'];
$our_score = $_POST['our_score'];
$opponent_score = $_POST['opponent_score'];
//Switch to the school's blog
switch_to_blog($channel_blog);
update_field('field_5215741f54e1f', $win_loss, $event_id ); // Win/Loss
update_field('field_5215744854e20', $our_score, $event_id ); // Our Score
update_field('field_5215746754e21', $opponent_score, $event_id ); // Opponent Score
// Restore Original Post Data
restore_current_blog();
The topic ‘update_field and switch_to_blog’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.