I updated the process_custom_taxonomies
function to the following, which solved my issue. It should be able to handle fields with array values (like checkboxes) as well as single values (text inputs), but I haven’t tested the latter myself.
function process_custom_taxonomies($feed, $entry, $post_id) {
$custom_taxonomies = rgars($feed, 'meta/custom_tax_settings');
foreach ($custom_taxonomies as $taxonomy_setting) {
$taxonomy = $taxonomy_setting['key'];
$field_id_base = $taxonomy_setting['value']; // Base ID for the field
// Check if the base field ID directly exists in the entry (for single value fields like text inputs)
if (isset($entry[$field_id_base]) && !empty($entry[$field_id_base])) {
$term_ids_or_slugs = [$entry[$field_id_base]]; // Treat the value as an array with a single element
} else {
// Collect all checked values for this taxonomy (for checkbox fields)
$term_ids_or_slugs = [];
foreach ($entry as $key => $value) {
if (strpos($key, $field_id_base . '.') === 0 && !empty($value)) { // Check if key starts with the base field ID
$term_ids_or_slugs[] = $value;
}
}
}
// Set terms if any values were provided
if (!empty($term_ids_or_slugs)) {
wp_set_object_terms($post_id, $term_ids_or_slugs, $taxonomy, false); // false to overwrite existing terms
}
}
}