Documentation

ACF Custom Database Tables v1.1

Introduction

What is this plugin?

The ACF Custom Database Tables plugin is an extension for the Advanced Custom Fields plugin. The extension makes it possible for developers to generate custom database tables that map to ACF Field Groups where each field represents a column. This approach provides the option to store key entity (post, user, custom post type) metadata as a single row of normalized data.

Features include:

  1. Table generation, creation, and modification from the WordPress admin
  2. Filters to prevent particular fields from generating a column
  3. Filters to disable core metadata storage where a custom table is available for that data
  4. Filters to enable join tables for eligible ACF field types
  5. Filters to remove support for particular fields

Why would I use it?

The plugin offers a few key benefits:

  1. Organised, structured data is more readily available for export and can be searched efficiently.
  2. By moving data out of the WordPress core meta tables, these tables can be more efficient in their own operations.
  3. Increased efficiency in database operations frees up system resources increasing scalability of your site/application.
  4. Advanced use offers join tables for eligible fields opening up the possibility of relationship-oriented custom SQL queries.

How does it work?

The basic process is as follows:

  1. The plugin introduces an option on an ACF Field Group’s admin page the allows a site administrator to enable a custom database table for that field group.
  2. On Field Group save, a JSON file is generated – this is the table definition.
  3. On a subsequent, manually-triggered action, these JSON files are converted to SQL and are then used to create new database tables or modify existing ones. A table map is also generated as part of this process.
  4. The plugin uses the generated map to intercept metadata as it is saved and retrieved from the database. If that piece of metadata has a custom table defined for the related object (post, user, custom post type), the data will be stored/retrieved to/from that custom table.

Basic requirements

The basic requirements for the plugin to function are as follows:

  1. PHP version 7.0
  2. WordPress version 5.7
  3. ACF version 5.10

Note: the plugin may work on older versions but we do develop for modern versions so it is best to remain updated at all times.

ACF Local JSON

Whilst not a requirement, we highly recommend using ACF JSON. Doing so enables you to further reduce the amount of metadata in your core meta tables by disabling ACF field key reference storage.

Enabling ACF JSON is as simple as creating an acf-json directory inside your theme directory. See https://www.advancedcustomfields.com/resources/local-json/ for further information.

If you decide to bypass both values and field key references you must have ACF JSON enabled and have all field groups saved in JSON format in order for ACF to work correctly. Without field key references in the database, ACF relies on the ACF JSON field groups to determine field mappings. Without those, data will not be stored correctly.

Supported field types

The plugin currently supports all built-in field types except for the following:

  1. Group
  2. Flexible Content
  3. Clone

The above fields are complex and support for these field types will ship in a future 1.x release.

Where a field type is unsupported, it will be ignored by the plugin and will be passed back to ACF to be handled as per usual (stored in core metatables).

Layout fields such as message, accordion, and tab are not considered as they do not store data.

Custom Field Types

There is some basic support in place for custom field types, but these field types need to be enabled/registered through the use of a simple WordPress filter. See activating support for a custom field type for instructions on how to do this.

Spot an issue? Please let us know about it.

Good dev stuff, delivered.

Product news, tips, and other cool things we make.

We never share your data. Read our Privacy Policy

© 2016 – 2024 Hookturn Digital. All rights reserved.