Support

Account

Home Forums General Issues update_field not working on comments

Helping

update_field not working on comments

  • I have a custom field on comments for subscribing option but it doesn’t get populated using the upadte_field() method.

    I am creating the comment dynamically and updating after I create it. The code looks like:

    $insertedCommentID = wp_new_comment($data, true);
    
    	if ($insertedCommentID) {
    		update_field('field_5abe804d6db31', isset($_POST['subscribe']) && $_POST['subscribe'] == 'true' ? 1 : 0, $insertedCommentID);
    	}

    I create the comment using the wp_new_comment (that returns the comment id) and then update the field (using the field_key instead of the field name) but nothing happens. I’ve tried other fields (text fields, text area, etc), with no success.

  • 
    $insertedCommentID
    

    is just the comment ID. The value that ACF needs is "comment_{$insertedCommentID}"

    https://www.advancedcustomfields.com/resources/get-values-comment/, the same syntax as getting values needs to be used for updating.

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

The topic ‘update_field not working on comments’ is closed to new replies.