Support

Account

Home Forums General Issues Update_field() not working for post_object fields.

Solving

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.

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

You must be logged in to reply to this topic.