eduardo-marcolino / acf-fields-in-custom-table

Stores ACF custom fields in a custom table instead of WordPress' core meta tables
27 stars 12 forks source link

Cannot delete fields in custom table #13

Closed dahuangfeng123 closed 3 years ago

dahuangfeng123 commented 3 years ago

Hi guys,Here is some useful information. WordPress 5.7.2 ACF: Fields in Custom Table Version 0.5 Advanced Custom Fields Version 5.9.6 11111111 222222222222222222

eduardo-marcolino commented 3 years ago

Hi @dahuangfeng123 .

The plugin uses wordpress core function dbDelta. dbDelta can add or alter columns, but not drop them.

You can implement your own delete routine by hooking into acf/update_field_group and use maybe_drop_column function:

add_action( 'acf/update_field_group', function( $field_group ) {

      // Skip if the custom table is not enable
      if ( !$field_group[self::SETTINGS_ENABLED]) {
        return;
      }

     $tablename = $field_group[ACF_FICT::SETTINGS_TABLE_NAME];
     // Add your code to drop columns
});
dahuangfeng123 commented 3 years ago

Great!