This tutorial is for developers.
Columns are registered in the lifecycle hook:
add_action('vg_sheet_editor/editor/before_init', array($this, 'register_columns'));
One column means a visible column in the spreadsheet, which is displayed in the spreadsheet editor, and in the import, and export tools.
One column does not mean one field in the database. Most columns are mapped one-to-one with a field like the post title, but we can also register multiple columns that save changes into the same database field, like we do for serialized columns.
Types of columns
We have many types of columns like text, select dropdown, checkbox, tinymce editor, and many more.
How to register a new column without code
You can go to wp-admin > wp sheet editor > custom columns.
And we have an interface where you can create columns with formatting by filling a form.
How to modify the settings of an existing column
You can go to the spreadsheet editor > columns manager. You will see the option to rename all the columns (change column name), and some columns have the option to change the formatting (for example, convert a text column into a dropdown, checkbox, file upload, etc.).
You should always use the interface because it will handle all the tricky scenarios for you automatically.
And you should use the code snippets only if you need something very advanced that’s not possible with the interface.
How to modify column settings programmatically
1- You need to find the field key that you want to edit in the database.
For example, if you want to add a column for the post meta: my_car_model , which contains a simple text as value.
2- You need to identify the spreadsheet key.
Open the spreadsheet and you will see the key in the URL, the text after “vgse-bulk-edit-” is the key. for example:
/wp-admin/admin.php?page=vgse-bulk-edit-post
3- Here’s an example of the code to register the column:
add_action('vg_sheet_editor/editor/before_init', array($this, 'register_columns')); function register_columns($editor) { // this is the spreadsheet key $post_type = 'product'; // we verify that this is registering the spreadsheet that we need, // remember that multiple spreadsheets might run on the same site if (!in_array($post_type, $editor->args['enabled_post_types'])) { return; } // This registers a taxonomy column with a dropdown $editor->args['columns']->register_item('my_category', $post_type, array( 'data_type' => 'post_terms', 'column_width' => 150, 'title' => __('Type', 'myplugin'), 'supports_formulas' => true, 'formatted' => array('type' => 'autocomplete', 'source' => 'loadTaxonomyTerms'), )); // This registers a multiple file upload column $editor->args['columns']->register_item('my_gallery', $post_type, array( 'data_type' => 'meta_data', 'unformatted' => array('renderer' => 'html', 'readOnly' => true), 'column_width' => 300, 'supports_formulas' => true, 'title' => __('My gallery', 'myplugin'), 'type' => 'boton_gallery_multiple', 'formatted' => array( 'renderer' => 'html', 'readOnly' => true), )); // This registers a normal text column $editor->args['columns']->register_item('my_model', $post_type, array( 'data_type' => 'meta_data', 'column_width' => 150, 'title' => __('My model', 'myplugin'), 'supports_formulas' => true, // We must use the slow execution method to sync with the lookup table 'supports_sql_formulas' => false, )); }
All the columns registered with this sample code can be registered without code using the “custom columns” page in our plugin. The code is useful if you want to register dynamic columns or you want something more advanced than the UI allows.