Home Forums General Issues update_field not updating fiel Reply To: update_field not updating fiel

  • Per far above, I have already tried;

    update_sub_field(field_64c782fc4c55d, 84, 1074);

    and it does not work even if the value changes.

    I found update_sub_field(); in /plugins/advanced-custom-fields-pro/includes/api/api-templated. I added some debugging code to it, too.

    function update_sub_field( $selector, $value, $post_id = false ) {
    	// vars
    	$sub_field = false;
    	// get sub field
    	if ( is_array( $selector ) ) {
    		$post_id   = acf_get_valid_post_id( $post_id );
    		$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
    	} else {
    		echo 'The $selector is '.$selector.', the $value is '.$value.' and the $post_id is '.$post_id;
    		echo ' Also, this is not an array</br>';
    		$post_id   = acf_get_loop( 'active', 'post_id' );
    		echo 'post_id: '.$post_id.'</br>';
    		$sub_field = get_row_sub_field( $selector );
    		echo 'sub_field: '.$sub_field.'</br>';
    		echo $post_id;
    	// bail early if no sub field
    	if ( ! $sub_field ) {
    		echo "not a sub_field</br>";
    		return false;
    	// update
    	echo "hello".$value.'//'.$post_id.'//'.$sub_field.'</br>';
    	return acf_update_value( $value, $post_id, $sub_field );

    The output of the above is;

    The $selector is field_64c782fc4c55d, the $value is 84 and the $post_id is 1074 Also, this is not an array
    not a sub_field

    post_id is not returned, sub_field is not return and it bails early as it is not a sub_field.