Title: wpdb::get_col_charset
Published: April 23, 2015
Last modified: May 20, 2026

---

# wpdb::get_col_charset( string $table, string $column ): string|false|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

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

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

Retrieves the character set for the given column.

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

 `$table`stringrequired

Table name.

`$column`stringrequired

Column name.

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

 string|false|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
Column character set as a string. False if the column has no character set. [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object if there was an error.

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

    ```php
    public function get_col_charset( $table, $column ) {
    	$tablekey  = strtolower( $table );
    	$columnkey = strtolower( $column );

    	/**
    	 * Filters the column charset value before the DB is checked.
    	 *
    	 * Passing a non-null value to the filter will short-circuit
    	 * checking the DB for the charset, returning that value instead.
    	 *
    	 * @since 4.2.0
    	 *
    	 * @param string|null|false|WP_Error $charset The character set to use. Default null.
    	 * @param string                     $table   The name of the table being checked.
    	 * @param string                     $column  The name of the column being checked.
    	 */
    	$charset = apply_filters( 'pre_get_col_charset', null, $table, $column );
    	if ( null !== $charset ) {
    		return $charset;
    	}

    	// Skip this entirely if this isn't a MySQL database.
    	if ( empty( $this->is_mysql ) ) {
    		return false;
    	}

    	if ( empty( $this->table_charset[ $tablekey ] ) ) {
    		// This primes column information for us.
    		$table_charset = $this->get_table_charset( $table );
    		if ( is_wp_error( $table_charset ) ) {
    			return $table_charset;
    		}
    	}

    	// If still no column information, return the table charset.
    	if ( empty( $this->col_meta[ $tablekey ] ) ) {
    		return $this->table_charset[ $tablekey ];
    	}

    	// If this column doesn't exist, return the table charset.
    	if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) {
    		return $this->table_charset[ $tablekey ];
    	}

    	// Return false when it's not a string column.
    	if ( empty( $this->col_meta[ $tablekey ][ $columnkey ]->Collation ) ) {
    		return false;
    	}

    	list( $charset ) = explode( '_', $this->col_meta[ $tablekey ][ $columnkey ]->Collation );
    	return $charset;
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wpdb/get_col_charset/?output_format=md#hooks)󠁿

 [apply_filters( ‘pre_get_col_charset’, string|null|false|WP_Error $charset, string $table, string $column )](https://developer.wordpress.org/reference/hooks/pre_get_col_charset/)

Filters the column charset value before the DB is checked.

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

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

Retrieves the character set for the given table.

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

Calls the callback functions that have been added to a filter hook.

  | 
| [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.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wpdb/get_col_charset/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wpdb/get_col_charset/?output_format=md#)

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

Strips any invalid characters from the string for a given table and column.

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

Adds field charsets to field/value/format arrays generated by [wpdb::process_field_formats()](https://developer.wordpress.org/reference/classes/wpdb/process_field_formats/).

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

Inserts or updates a post in the database.

  |

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

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

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Fget_col_charset%2F)
before being able to contribute a note or feedback.