Thursday 29 November 2018

Managing WordPress Custom Tables with an ACF Repeater Field


Whilst working on the deliciousbrains.com site we had the need to store some data about a custom post type. Because of the nature of the data it didn’t make sense to try and shoehorn it into the post meta table as a serialized array. Instead, creating a custom table to store it was the better approach. We want our customers to be able to download the latest version of the plugin at the time their license expired. We use WooCommerce to sell our WordPress plugins, but that only stores the current product version in post meta.
To implement this functionality we need to store all of the versions for a plugin with the date they were released, and the zip filename. The custom table structure would look like this:
CREATE TABLE `wp_woocommerce_software_product_versions` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`product_id` bigint(20) NOT NULL,
`version` varchar(200) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`filename` varchar(200) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`date_released` datetime NOT NULL DEFAULT ‘0000-00-00 00:00:00’,
`created_at` timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’,
`updated_at` timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’,
PRIMARY
Source: https://managewp.org/articles/18153/managing-wordpress-custom-tables-with-an-acf-repeater-field



source https://williechiu40.wordpress.com/2018/11/29/managing-wordpress-custom-tables-with-an-acf-repeater-field/

No comments:

Post a Comment