acf_ct/set_sql_data_type

Used to change SQL data type of the field

By default, the SQL column data type is set based on the ACF field type.

Parameters

apply_filters( "acf_ct/set_sql_data_type", $type, $field, $table_name);
  • $type Default SQL data type
  • $field ACF field array
  • $table_name Custom table name

Modifiers

This filter provides modifiers to target specific fields. The following filter names are available:

  • acf_ct/set_sql_data_type Applies to all fields.
  • acf_ct/set_sql_data_type/key={$type} Applies to all fields of a specific type.
  • acf_ct/set_sql_data_type/name={$name} Applies to all fields of a specific key.

Example

function change_sql_data_type($type, $field, $table_name){

	if($table_name === 'wp_products'){

		if($field['name'] === 'status'){
			return 'MEDIUMINT(9)';
		}

	}else if($table_name === 'wp_orders'){

		if($field['key'] === 'field_123abcf'){
			return 'LONGTEXT';
		}

	}

	return $type;
}

// Apply to all fields.
add_filter('acf_ct/set_sql_data_type', 'change_sql_data_type', 10, 3);

// Apply to fields named "status".
add_filter('acf_ct/set_sql_data_type/name=status', 'change_sql_data_type', 10, 3);

// Apply to field with key "field_123abcf".
add_filter('acf_ct/set_sql_data_type/key=field_123abcf', 'change_sql_data_type', 10, 3);

Upgrade to PRO