GithubHelp home page GithubHelp logo

victoriusnet / acf-fields-in-custom-table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eduardo-marcolino/acf-fields-in-custom-table

0.0 0.0 0.0 186 KB

Stores ACF custom fields in a custom table instead of WordPress' core meta tables

PHP 100.00%

acf-fields-in-custom-table's Introduction

ACF: Fields in Custom Table

This ACF plugin makes it possible to store ACF data in structured database tables instead of WordPress core meta tables.

It uses ACF's acf/update_field_group hook to create/update the database and then uses acf/save_post hook to store the data.

It was heavily inspired by Austin Ginder's post https://anchor.host/acf-custom-fields-stored-in-custom-table/.

Supported Fields

  • Text
  • Text Area
  • Number
  • Range
  • Email
  • URL
  • Password
  • Image
  • File
  • Wysiwyg Editor
  • oEmbed
  • Select
  • Checkbox
  • Radio Button
  • Button Group
  • True / False
  • Date Picker
  • Date Time Picker
  • Time Picker
  • Color Picker
  • Link
  • Post Object
  • Page Link
  • Relationship
  • Taxonomy
  • User

Relational Fields

This plugin supports the following relational field types: Post Object, Page Link, Relationship, Taxonomy and User.

It can store both single and multiple values based on the multiple option.

  • If it's a single value field, then the column type will be bigint(20) unsigned
  • If it's a multiple value field, then the column type will be longtext and the date will be stored in json format.

You can query relational fields with multiple values using using MySQL's function JSON_CONTAINS. Here is an example:

Table:

+---------+-------------------+--------+
| post_id |       title       | stores |
+---------+-------------------+--------+
|       1 | Lord of the Flies | [1,2]  |
|       2 | The Island        | [2]    |
|       3 | 1984              | [3]    |
+---------+-------------------+--------+

Query:

SELECT * FROM wp_acf_books WHERE JSON_CONTAINS(stores, 2, '$')

The query above will return "Lord of the Flies" and "The Island"

Filters

The plugin provides filters to allow developers to customize the plugin behavior:

Chaging table prefix

add_filter( 'acfict_table_prefix', function( $prefix, $tablename ) {
  return 'newprefix_';
}, 10, 2);

Disabling WP Post Meta storage

By default the data is still stored in WP Post Meta but you can disable it using acf filter acf/pre_update_value as such:

//Will disable WP Post Meta storage for all field groupd with "ACF: Fields in Custom Table" enabled.
add_filter( 'acf/pre_update_value', function( $default, $value, $post_id, $field )
{
  if( $field[ACF_FICT::SETTINGS_ENABLED] ) {
    return false;
  }

  return $default;
}, 10, 4);

ACF Compatibility

This plugin was tested with ACF 5 FREE Version .

Screenshots

01

acf-fields-in-custom-table's People

Contributors

eduardo-marcolino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.