Last active
August 29, 2015 14:14
-
-
Save tobz-nz/2bda59070e0613d41b8c to your computer and use it in GitHub Desktop.
Create a simple text field for Expressionengine via sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SET @fieldGroupId = 1; -- your field group id | |
| SET @fieldName = 'Your_field_name'; | |
| SET @fieldUrlLabel = 'Your Field Label'; | |
| -- create the field record | |
| INSERT INTO `exp_channel_fields` (`site_id`, `group_id`, `field_name`, `field_label`, `field_instructions`, `field_type`, `field_list_items`, `field_pre_populate`, `field_pre_channel_id`, `field_pre_field_id`, `field_ta_rows`, `field_maxl`, `field_required`, `field_text_direction`, `field_search`, `field_is_hidden`, `field_fmt`, `field_show_fmt`, `field_order`, `field_content_type`, `field_settings`) | |
| VALUES (1, @fieldGroupId, @fieldName, @fieldUrlLabel, '', 'text', '', '0', 0, 0, 6, 128, 'y', 'ltr', 'n', 'n', 'none', 'n', 9, 'any', 'YTo3OntzOjE4OiJmaWVsZF9jb250ZW50X3R5cGUiO3M6MzoiYWxsIjtzOjE4OiJmaWVsZF9zaG93X3NtaWxleXMiO3M6MToibiI7czoxOToiZmllbGRfc2hvd19nbG9zc2FyeSI7czoxOiJuIjtzOjIxOiJmaWVsZF9zaG93X3NwZWxsY2hlY2siO3M6MToibiI7czoyNjoiZmllbGRfc2hvd19mb3JtYXR0aW5nX2J0bnMiO3M6MToibiI7czoyNDoiZmllbGRfc2hvd19maWxlX3NlbGVjdG9yIjtzOjE6Im4iO3M6MjA6ImZpZWxkX3Nob3dfd3JpdGVtb2RlIjtzOjE6Im4iO30='); | |
| -- Create the field column | |
| SET @id = (SELECT MAX(field_id) FROM exp_channel_fields); | |
| SET @field = CONCAT('field_id_', @id); | |
| SET @fieldType = CONCAT('field_ft_', @id); | |
| SET @query = CONCAT('ALTER TABLE `exp_channel_data` ADD COLUMN ', @field, ' TEXT, ADD COLUMN ', @fieldType, ' TINYTEXT'); | |
| PREPARE stmt FROM @query; | |
| EXECUTE stmt; | |
| DEALLOCATE PREPARE stmt; | |
| -- add the formatting | |
| INSERT INTO `exp_field_formatting` (`field_id`, `field_fmt`) VALUES (@id, 'none'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment