Support

Account

Home Forums General Issues get_field() returning array for Select when no value exists in database Reply To: get_field() returning array for Select when no value exists in database

  • Temporary workaround for anyone else having this issue:

    function coerce_array_to_value( $value, $post_id, $field ) {
      if (
        $field['return_format'] === 'value' &&
        !$field['multiple'] &&
        is_array( $value ) &&
        array_key_exists( 0, $value )
      ) {
        $value = $value[0];
      }
    
      return $value;
    }
    
    add_filter( 'acf/load_value/type=select', array( $this, 'coerce_array_to_value' ), 10, 3 );