Home › Forums › General Issues › Update_field() not working for post_object fields.
I’m having some issues with a plugin I’m writing where no matter what information I feed update_field()
, any post object field I attempt to change is unaffected. The field is set up accept the post
post type, and is restricted to two categories. It can only accept one post, and null is disallowed. The function looks like this:
update_field( 'field_xxx', $postid, $targetpostid);
I’ve tried passing $postid
which has a value of 812 as a string, an integer, an array, and even as a post object by setting $postid = get_post(812)
. I’ve also verified that the post is in the correct category, yet still, every time I open the target post, the post object field is empty. I’m at a bit of a loss as to where to go from here, so any insight will be greatly appreciated.
Further Elaboration of the code.
function custom_post_generator($posttitle,$parentpostID,$item,$postnum){
$post_info = array (
'post_type'=>'custom_post_type',
'post_title' => $posttitle,
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',);
$postID = wp_insert_post($post_info);
//parent post, post object field
update_field('field_62a908d5690ce', $parentpostID, $postID);
The only thing I can think of is that a post object field holds an array of post IDs
update_field('field_62a908d5690ce', array($parentpostID), $postID);
I was actually too hasty on this and I can’t edit it anymore. The post object field is accepting the value of $postid
formatted as an int
, but it’s not displaying in the edit post screen, it’s just showing up as an empty field.
Any news here? I’m facing the same situation in my project. When I try to update the post object field dynamically, it stays blank. I’ve already tried to send it as an Array and/or with the field ID but it didn’t work either.
In my case the post is already created. This is not a newly created post. I don’t know if there is any difference in this case to the previously mentioned from @toneseeker
Hoping for a suggestion
It’s been almost 3 months since I looked at this issue, I got it “working”, but there were issues so I dropped ACF and added the custom fields to the post type manually. If I remember correctly, the data was “there”, as in associated with the post and custom field, but the field was never populated in the UI.
Use mastectomy products like mastectomy bras or prosthesis. Pink Ribbon, helps you feel good about the way you look. Our collection cannot be beaten.
You must be logged in to reply to this topic.
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.