Title: wpdb::process_field_lengths
Published: April 27, 2015
Last modified: February 24, 2026

---

# wpdb::process_field_lengths( array $data, string $table ): array|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#wp--skip-link--target)

For string fields, records the maximum string length that field can safely save.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#parameters)󠁿

 `$data`arrayrequired

Array of values, formats, and charsets keyed by their field names, as it comes from
the [wpdb::process_field_charsets()](https://developer.wordpress.org/reference/classes/wpdb/process_field_charsets/)
method.

 * `...$0` array
 *  Value, format, and charset for this field.
    - `value` mixed
    - The value to be formatted.
    - `format` string
    - The format to be mapped to the value.
    - `charset` string|false
    - The charset to be used for the value.

`$table`stringrequired

Table name.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#return)󠁿

 array|false The same array of data with additional ‘length’ keys, or false if information
for the table cannot be found.

 * `...$0` array
 *  Value, format, charset, and length for this field.
    - `value` mixed
    - The value to be formatted.
    - `format` string
    - The format to be mapped to the value.
    - `charset` string|false
    - The charset to be used for the value.
    - `length` array|false
    -  Information about the maximum length of the value.
       False if the column has
      no length.
       * `type` string
       * One of `'byte'` or `'char'`.
       * `length` int
       * The column length.
          }

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#source)󠁿

    ```php
    protected function process_field_lengths( $data, $table ) {
    	foreach ( $data as $field => $value ) {
    		if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
    			/*
    			 * We can skip this field if we know it isn't a string.
    			 * This checks %d/%f versus ! %s because its sprintf() could take more.
    			 */
    			$value['length'] = false;
    		} else {
    			$value['length'] = $this->get_col_length( $table, $field );
    			if ( is_wp_error( $value['length'] ) ) {
    				return false;
    			}
    		}

    		$data[ $field ] = $value;
    	}

    	return $data;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wpdb.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wpdb.php#L2997)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wpdb.php#L2997-L3016)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#related)󠁿

| Uses | Description | 
| [wpdb::get_col_length()](https://developer.wordpress.org/reference/classes/wpdb/get_col_length/)`wp-includes/class-wpdb.php` |

Retrieves the maximum string length allowed in a given column.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

| Used by | Description | 
| [wpdb::process_fields()](https://developer.wordpress.org/reference/classes/wpdb/process_fields/)`wp-includes/class-wpdb.php` |

Processes arrays of field/value pairs and field formats.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wpdb/process_field_lengths/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.2.1](https://developer.wordpress.org/reference/since/4.2.1/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Fprocess_field_lengths%2F)
before being able to contribute a note or feedback.