After digging through the plugin’s source code, I’ve came to conclusion that currently it’s impossible to use the plugin with programmatically registered field groups.
Plugin assumes that all ACF groups have appropriate acf-field-group
post to fetch groups’ settings, which is incorrect when using acf_add_local_field_group
As a hacky workaround I’ve done the following:
- Passed
acf_ct_enable
and acf_ct_table_name
to acf_add_local_field_group()
- Manually assigned keys to the fields I want to sync with custom table so they were matching with names.
- Manually created MySQL table by creating a field group in GUI with the same structure as programmatically registered one, then using plugin’s generated sql code as an example.
- Hacked plugin’s
acf_ct_handle_save_post
hook handler:
…
$acf_groups = Acfct_utils::acf_get_field_groups_id($post_id);
$groups = acf_get_field_groups(Acfct_utils::get_field_groups_filter_array($post_id));
$formatted_post_id = Acfct_utils::format_post_id($post_id);
…
foreach ($groups as $group) {
$acf_post_id = $group[‘ID’];
$custom_table = $group[‘acf_ct_table_name’] ?? false;
if ($custom_table === false) {
continue; //Custom table is not enabled
}
$custom_table = $wpdb->prefix . $custom_table;
if (Acf_ct_database_manager::check_table_exists($custom_table) === false) {
continue; //Custom table is not exists
}
$store_acf_values_in_post_meta = apply_filters(‘acf_ct/settings/store_acf_values_in_post_meta’, true);
$acfKeyMap = Acfct_utils::get_acf_keys($group[‘key’], true);
$dbHandler = new Acfct_table_data($formatted_post_id, $custom_table);
…
After that, I’ve got custom table being populated on save.
-
This reply was modified 8 months ago by selim13.