Home Forums Bug Reports Trying to access offset value of type bool Reply To: Trying to access offset value of type bool

  • One of ACF’s function is returning false when looking by field name. What you’re going to need to do is check to see if the field has a value before attempting to delete it.

    function delete_field( $selector, $post_id = false ) {
    	// filter post_id
    	$post_id = acf_get_valid_post_id( $post_id );
    	// get field
    	$field = acf_maybe_get_field( $selector, $post_id );
    	// delete
    	return acf_delete_value( $post_id, $field );

    acf_maybe_get_field() is returning false
    acf_delete_value() expects $field to be an array, which it is not.

    The last line of this function should likely be

    if ($field) {
      return acf_delete_value( $post_id, $field );

    of the function acf_delete_value() should be checking to see if $field has a value before attempting to use it.

    I would call this a bug. You should submit it here

    In the mean time, as a fix, you can either use the field key when calling these or check for a value.

    I would use the field key because as I already mentioned update_field() using the field name where the field does not already have a value will fail to save a value. This is covered in the documentation for this function