Home › Forums › General Issues › ACF Update Field – Error
Hi all,
I feel like I am going round in circles here.
I am using ACF 4.4.1 with WP 4.2.2
I have a strange problem, I have two forms on a site, both have similar code to insert a custom post. One form will insert a post type of ‘review’ and it has a relationship field, which is associated with a post type of ‘listing’.
The code inserts the post then updates ACF fields using the update field API
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['insert_post'] )) { //check that our form was submitted
$title = $_POST['reviewTitle']; //set our title
$comments = $_POST['comments']; //set our comments field
$name = $_POST['reviewerName']; //set our name field
$email = $_POST['email']; //set our email field
$featureRating = $_POST['featureRating']; //set our feature rating field
$easeRating = $_POST['easeRating']; //set our ease of use rating field
$valueRating = $_POST['valueRating']; //set our value rating field
$relatedListingId = array($currentPostId); // add our current post ID as the related listing ID, ACF relationship field expects an array
$newReviewPost = array( //our wp_insert_post args
'post_title' => wp_strip_all_tags($title),
'post_status' => 'publish',
'post_type' => 'review',
);
$postId = wp_insert_post($newReviewPost); //insert our post, return the resulting ID as $postId
update_field('field_id', $name, $postId); // update name
update_field('field_id', $email, $postId); // update email
update_field('field_id', $comments, $postId); // update comments
update_field('field_id', $relatedListingId, $postId); //update our related listing ID - links the review to this product listing
update_field('field_id', $featureRating, $postId); update_field('field_id', $easeRating, $postId);
update_field('field_id', $valueRating, $postId);
header('Location: '.$_SERVER['REQUEST_URI']); // refresh our page, to show the review.
}
This form works fine.
I have another form that is a contact us form, and inserts a post type of “contact” and has no relationship. It uses essentially the same code but without the relationship. This causes the white screen of death!
If I remove the ACF update field code, the post inserts fine. I am totally stumped, any help would be greatly appreciated as I am up against a deadline and this has had me tearing my hair out for over a day now.
if( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty( $_POST[‘insert_post’] )) { //check that our form was submitted
$title = $_POST[‘postTitle’]; //set our title
$name = $_POST[‘name’]; //set our name field
$newPost = array( //our wp_insert_post args
‘post_title’ => wp_strip_all_tags($title),
‘post_status’ => ‘publish’,
‘post_type’ => ‘contact’,
);
$postId = wp_insert_post($newPost); //insert our post, return the resulting ID as $postId
echo “Post id ” . $postId;
update_field(‘field_id’, $name, $postId); // update name
}
Many thanks
Lee
Hi @leemg
Hmm… Try increasing the memory allocated to PHP. You can do this either through editing wp-config.php file or php.ini
If this does not work, you could try enabling wp_debug to see if any errors display. These errors will point you to what is causing the problem.
Thanks James, I tried this to no avail, however I noticed that one of my inputs had a name of “name” e.g <input type=”text “name=”name”> I changed this and it worked! I have no idea why this would cause a problem 🙂
Thanks for you help.
The topic ‘ACF Update Field – Error’ 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.