Thanks, I tested the ts_checkboxes() approach from that ticket.
The function runs without errors, but the checkbox state still doesn’t appear in the Toolset field UI. What I’m seeing is that values are saved to wp_postmeta (e.g. 1,2,3 or labels), but it seems Toolset only recognizes checkboxes as selected when its internal option-hash keys are present (e.g. wpcf-fields-checkboxes-option-<hash>-1).
Since Gravity Forms / APC saves plain values, the Toolset UI ignores them on reload.
Is there a supported way to programmatically map numeric values (1,2,3) to Toolset checkbox option keys on save, or are Toolset checkbox fields just not intended to be populated externally?
This is the code I am using:
[code]
function ts_checkboxes( $post_id, $field, $option, $action = 'check' ) {
if ( empty($post_id) || empty($field) || empty($option) ) {
return;
}
// Get Toolset field definition
$field_settings = types_get_field( $field );
if ( empty($field_settings['data']['options']) ) {
return;
}
$field_options = $field_settings['data']['options'];
// Find internal option key by TITLE
$titles = array_column( $field_options, 'title' );
$index = array_search( $option, $titles, true );
if ( $index === false ) {
error_log('[Loan Intake] Option not found: ' . $option);
return;
}
$option_keys = array_keys( $field_options );
$option_key = $option_keys[$index];
// Load current meta
$meta_key = 'wpcf-' . $field;
$meta = get_post_meta( $post_id, $meta_key, true );
if ( ! is_array($meta) ) {
$meta = [];
}
// Uncheck first
unset( $meta[$option_key] );
// Check if requested
if ( $action === 'check' ) {
$meta[$option_key] = [ $field_options[$option_key]['set_value'] ];
}
update_post_meta( $post_id, $meta_key, $meta );
error_log('[Loan Intake] Checked ' . $field . ' → ' . $option);
}
add_filter(
'gform_advancedpostcreation_post_after_creation_2',
function ( $post_id, $feed, $entry, $form ) {
// GF field → Toolset field map
$maps = [
101 => 'client-collateral-type-2',
85 => 'client-loan-purpose',
63 => 'client-main-customer-type',
];
$selections = [];
foreach ( $maps as $gf_field_id => $toolset_field ) {
$field = GFAPI::get_field( $form, $gf_field_id );
if ( ! $field || $field->type !== 'checkbox' ) {
continue;
}
foreach ( $field->inputs as $input ) {
$value = rgar( $entry, (string) $input['id'] );
if ( ! empty( $value ) ) {
$selections[] = [
'field' => $toolset_field,
'option' => $value,
];
}
}
}
// Run AFTER everything else
add_action( 'admin_init', function () use ( $post_id, $selections ) {
foreach ( $selections as $item ) {
ts_checkboxes(
$post_id,
$item['field'],
$item['option'],
'check'
);
}
});
},
10,
4
);
[/code]