• Resolved justinosa

    (@justinosa)


    I have a list of checkboxes to set/update custom taxonomy values but the plugin removes all terms from the post that is being updated. I’ve tried setting the checkbox values to the term IDs, term slugs, and term labels without any luck.

    Any advice would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter justinosa

    (@justinosa)

    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
            }
        }
      }

    Plugin Author Alex Chernov

    (@alexusblack)

    Thank you for the fix @justinosa, sadly I’m too stripped for time recently to properly support this plugin.

    If I could ask you to make a pull request here – https://github.com/AlexusBlack/post-update-addon-gravity-forms I would be happy to release the fix as a new version.

    Thread Starter justinosa

    (@justinosa)

    @alexusblack — No problem. PR created!

    Thanks for the plugin!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Taxonomies Not Updating’ is closed to new replies.