Developers -- How to add new fields using the database
Posted by Howard R. on 26 August 2014 12:23 AM
Firstly, find out what kind of entity you want to add a new field. You can find WPL defined kinds on [wp_prefix]_wpl_kinds table. For example: the kind id of the property is 0 and the kind id of the user is 2.
1- Check the table column in the [wp_prefix]_wpl_kinds table and add a new column into the kind table. For example, if you want to add a new field for users you should add a new column into the [wp_prefix]_wpl_users table.
2- Add a new record into the [wp_prefix]_wpl_dbst table. These columns are important when adding this record:
- id: You should find the maximum ID of dbst records for setting this ID. (Maximum+1) The Minumum value for ID is 3000. So if Maximum+1 is less than 3000, you should pick 3000 for the ID.
- kind: Insert kind id from [wp_prefix]_wpl_kinds table.
- name: Insert the name of your field.
- type: Insert your field type. In most of cases, clients need to add a text, textarea, number or select field.
- options: To insert options for this field based on the field you need, this must be in JSON encoded array. You can see other fields as a sample.
- enabled: It should be 1 or 2. 0 means it is disabled.
- table_name: Insert kind table from [wp_prefix]_wpl_kinds table.
- table_column: Insert the name of the column that you added in first step.
- category: Find category ID from [wp_prefix]_wpl_dbcat table and insert it in this column.
- pwizard: This should be 1 if you want to show it on wizards such as Add/Edit listing wizard or the user profile wizard, and should be 0 if you want to hide it.
Note: For some field types you may need to add more columns to the target table using a naming rule. For example: For neighborhood, features, price etc., you need to add more than 1 field to the target table. Please see the current fields as a sample.