Table creation/modification is a two part process:
- First, we need to generate (or update) the field group’s table definition JSON file.
- Then, we need to apply the definition to the database in order to create new tables or modify existing ones.
Generating the definition file
- Head to the field group you wish to create a table for.
- Make sure the field group has one object mapping in its location settings – Either User Form or Post Type will work
- Scroll down to the ACF Custom Database Table Settings meta box and toggle the Manage Table Definition option to Yes.
- Enter a table name for your table. You can only specify this once, so choose wisely. Changing this down the track is not impossible, but currently requires modification of post metadata for the field group and an SQL query to modify the database.
- In the Publish meta box, click Update.
- This will generate your table definition as a JSON file. Details of this will be output in the post updated message towards the top of the screen.
Applying the definition file to the database
- You can either click on the blue Manage Database Tables button in the post update message or you can head to Custom Fields > Database Tables > Manage Tables.
- Review the information on the screen and take a full backup of your database as per the instructions.
- When you are ready to apply the changes, click the confirmation check box and then click the blue Create/Update Tables button.
You’ll see the results from this action in the update message towards the top of the screen.
Note: the output is generated by WordPress’ built in database modification function and will report that a table was ‘created’ whether it already exists or not. If you see the ‘Created table xxx’ message for a table you’ve already created, it just means the table definition was passed through WordPress’ internal database modification process and any available modifications will have been applied to the table. Your data is still there, but in the unlikely event where data is lost, you’ll have your back up to roll back to.
Table creation is now done. Any data you save for the relevant object (post, user) will now be stored in the custom database table.