eduardo-marcolino/acf-fields-in-custom-table
Composer 安装命令:
composer require eduardo-marcolino/acf-fields-in-custom-table
包简介
ACF: Fields in Custom Table
README 文档
README
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
- 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
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2020-11-26
