Site icon Hip-Hop Website Design and Development

update_term_meta() solely updating as soon as on sure meta keys

I arrange 4 customized meta fields on a customized taxonomy, and for some motive the sector values for my 2 textual content fields solely replace the primary time they’re added to the database. Both from together with them within the "add" kind or if I create a taxonomy with out them after which embody them within the "edit" kind for the primary time. However as quickly as I attempt to change the values, the database doesn’t get up to date. What am I doing improper?

Right here is my code:

// Add the fields to the "groups" taxonomy, utilizing our callback perform  
add_action( 'groups_add_form_fields', 'groups_taxonomy_custom_fields', 10, 2 ); // "Add new" kind
add_action( 'groups_edit_form_fields', 'groups_taxonomy_custom_fields', 10, 2 ); // "Edit" kind
perform groups_taxonomy_custom_fields($time period) {
    // Get the web page
    world $pagenow;

    // Set empty vars
    $group = '';
    $email_domain = '';
    $facilitators = array();
    $access_ids = array();

    // If we're on the "add new" web page
    if ($pagenow == 'edit-tags.php') {
        // Desk setup
        $cont1 = '<div class="form-field">';
        $cont2 = '';
        $cont3 = '</div>';
        
    // If we're on the "edit" time period web page
    } elseif ($pagenow == 'time period.php') {
        // Test for current taxonomy meta for the time period you are modifying
        $term_id = isset($term->term_id) ? $term->term_id : null;
        $group = get_term_meta( $term_id, 'group', true );
        $email_domain = get_term_meta( $term_id, 'email_domain', true );
        if (get_term_meta( $term_id, 'facilitators', true )) {
            $facilitators = get_term_meta( $term_id, 'facilitators', true );
        }
        if (get_term_meta( $term_id, 'access_ids', true )) {
            $access_ids = get_term_meta( $term_id, 'access_ids', true );
        }

        // Desk setup
        $cont1 = '<tr class="form-field">  
        <th scope="row" valign="top">';
        $cont2 = '</th>  
        <td>';
        $cont3 = '</td>  
        </tr>';
        
    // Else nothing
    } else {
        $cont1 = '';
        $cont2 = '';
        $cont3 = '';
    }

    // Let's get all of the webinar codes
    $codes = get_terms( array(
        'taxonomy' => eri_access_id_taxonomy(),
        'hide_empty' => false,
        'order' => 'DESC',
    ) );

    // Now get all of the Facilitators
    $customers = get_users( array(
        'role__in'  => array( 'facilitator' ),
        'orderby'   => 'display_name',
        'order'     => 'ASC'
    ) );
    ?>  

    <!-- ADD SOME CSS -->
    <fashion>
    .yoast-notification {
        show: none;
    }
    .editor-training-groups-list {
        background: white;
        max-height: 20em;
        overflow: hidden;
        padding-left: 6px;
        padding-top: 6px;
        width: 94%;
        overflow-y:auto;
    }
    .editor-training-groups-choice {
        margin-bottom: 10px;
        float: left;
        clear: each;
    }
    .editor-code-label {
        vertical-align: prime !essential;
        show: inline !essential;
    }
    .training-type-title {
        font-weight: daring;
        float: left;
        clear: each;
        margin-bottom: 10px;
    }
    </fashion>

    <!-- ORGANIZATION FIELD -->
    <?php echo $cont1; ?>   
        <label for="organization"><?php _e('Group/Group'); ?></label>  
    <?php echo $cont2 ?? $cont2; ?>  
        <enter kind="text" title="organization" id="organization" dimension="25" worth="<?php echo $organization; ?>"><br />  
        <span class="description"><?php _e('The complete title of the group or group.'); ?></span>  
    <?php echo $cont3; ?>

    <!-- EMAIL DOMAIN FIELD -->
    <?php echo $cont1; ?>  
        <label for="email_domain"><?php _e('E-mail Area'); ?></label>  
    <?php echo $cont2 ?? $cont2; ?> 
        <enter kind="text" title="email_domain" id="email_domain" dimension="25" worth="<?php echo $email_domain; ?>"><br />  
        <span class="description"><?php _e('Your group's e mail area title  (after the @ image) that customers will largely be utilizing to register. (NOTE: Anyone who registers utilizing an e mail tackle with this area will probably be robotically added to this coaching group.)'); ?></span>  
    <?php echo $cont3; ?>

    <!-- FACILITATORS FIELD -->
    <?php echo $cont1; ?>  
        <span><?php _e('Facilitators'); ?></span>
    <?php echo $cont2 ?? $cont2; ?> 
        <div class="editor-training-groups-list">
            <?php
            // Vars
            $the_users_checked = [];
            $the_users = [];

            // Cycle by every person
            foreach ($customers as $person) {
                $is_checked = false;
                $checked = '';
                if (in_array($user->ID, $facilitators)) {
                    $is_checked = true;
                    $checked = ' checked="checked"';
                }

                $id = '<div class="editor-training-groups-choice">
                    <enter kind="hidden" worth="0" title="facilitators['.$user->ID.']">
                    <enter kind="checkbox" id="facilitators['.$user->ID.']" title="facilitators['.$user->ID.']" worth="1" '.$checked.'/><label for="facilitators['.$user->ID.']" class="editor-code-label">'.$user->display_name.' <span class="limit-length">('.$user->user_email.'): '.$user->group.'</span></label>
                </div>';

                if ($is_checked) {
                    $the_users_checked[] = $id;
                } else {
                    $the_users[] = $id;
                }
            }

            echo implode('', $the_users_checked);
            echo implode('', $the_users);
            ?>
        </div>  
        <span class="description"><?php _e('Choose the Facilitators that can have entry to this trainings dashboard.'); ?></span>  
    <?php echo $cont3; ?>

    <!-- TRAININGS FIELD -->
    <?php echo $cont1; ?>  
        <span><?php _e('Trainings'); ?></span>
    <?php echo $cont2 ?? $cont2; ?> 
        <div class="editor-training-groups-list">
            <?php
            // Let's get all the codes to create a hyperlink
            $tta_names = [];
            foreach ($codes as $code) {
                $code_names[] = strtolower($code->title);
            }

            // Create empty arrays to retailer them
            $tta_names = [];
            $ita_names = [];
            $uta_names = [];
            $tta_checked = [];
            $ita_checked = [];
            $uta_checked = [];
            $tta = [];
            $ita = [];
            $uta = [];

            // Cycle by every time period
            foreach ($codes as $code) {
                $is_checked = false;
                $checked = '';
                if (in_array($code->title, $access_ids)) {
                    $is_checked = true;
                    $checked = ' checked="checked"';
                }
                $code_title = get_the_title( $code->description );
                $li = '<div class="editor-training-groups-choice">
                    <enter kind="hidden" worth="0" title="access_ids['.$code->name.']">
                    <enter kind="checkbox" id="access_ids['.$code->name.']" title="access_ids['.$code->name.']" worth="1" '.$checked.'/><label for="access_ids['.$code->name.']" class="editor-code-label">'.$code->title.': <span class="limit-length">'.$code_title.'</span></label>
                </div>';
                
                if (eri_is_TTA($code->title)) {
                    $tta_names[] = strtolower($code->title);
                    if ($is_checked) {
                        $tta_checked[] = $li;
                    } else {
                        $tta[] = $li;
                    }
                } elseif (eri_is_ITA($code->title)) {
                    $ita_names[] = strtolower($code->title);
                    if ($is_checked) {
                        $ita_checked[] = $li;
                    } else {
                        $ita[] = $li;
                    }
                } elseif (eri_is_UTA($code->title)) {
                    $uta_names[] = strtolower($code->title);
                    if ($is_checked) {
                        $uta_checked[] = $li;
                    } else {
                        $uta[] = $li;
                    }
                }
            }

            // Title Extension
            $title_ext = ' Technical Help';
            $top_margin = '30px';
            $goal = "_blank";

            // Add the title and checklist objects
            if (!empty($tta_checked) || !empty($tta)) {
                echo '<div class="training-type-title">Focused'.$title_ext.': <a href="/wp-admin/edit.php?post_type=page&codes='.implode('%2C',$tta_names).'" goal="'.$target.'">('.rely($tta_names).')</a></div>';

                echo implode('', $tta_checked);
                echo implode('', $tta);
            }

            if (!empty($ita_checked) || !empty($ita)) 

            if (!empty($uta_checked) || !empty($uta))  !empty($ita)) ? ' fashion="margin-top: '.$top_margin.'"' : '';
                echo '<div class="training-type-title"'.$margin.'>Common'.$title_ext.': <a href="/wp-admin/edit.php?post_type=post&codes='.implode('%2C',$uta_names).'" goal="'.$target.'">('.rely($uta_names).')</a></div>';

                echo implode('', $uta_checked);
                echo implode('', $uta);
            
            ?>
        </div>  
        <span class="description"><?php _e('Choose the Webinar Codes this Coaching Group has entry to.'); ?></span>  
    <?php echo $cont3; ?>

    <?php
}  

// Save the adjustments made on the "groups" taxonomy, "add new" kind
add_action( 'created_groups', 'save_groups_new_custom_fields', 10, 2 );
perform save_groups_new_custom_fields( $term_id, $tt_id ) {  
    if ( isset($_POST['organization']) ) {  
        add_term_meta( $term_id, 'group', $_POST['organization'], true );
    }
    if ( isset($_POST['email_domain']) ) {  
        add_term_meta( $term_id, 'email_domain', $_POST['email_domain'], true );
    }
    if ( isset($_POST['access_ids']) ) {
        $aid_checked = [];
        $access_ids = $_POST['access_ids'];
        foreach ($access_ids as $key=>$worth) {
            if ($worth == '1'){
                $aid_checked[] = $key;
            }
        }
        add_term_meta( $term_id, 'access_ids', $aid_checked );
    }
    if ( isset($_POST['facilitators']) ) {
        $fac_checked = [];
        $facilitators = $_POST['facilitators'];
        foreach ($facilitators as $key=>$worth) {
            if ($worth == '1'){
                $fac_checked[] = $key;
            }
        }
        add_term_meta( $term_id, 'facilitators', $fac_checked );
    }
}
// Save the adjustments made on the "groups" taxonomy, "edit" kind
add_action( 'edited_groups', 'save_groups_existing_custom_fields', 10, 2 ); 
perform save_groups_existing_custom_fields( $term_id, $tt_id ) {  
    if ( isset($_POST['organization']) ) {
        update_term_meta( $term_id, 'group', $_POST['organization'], true ); // <-- ONLY UPDATING ONCE
    }
    if ( isset($_POST['email_domain']) ) {
        update_term_meta( $term_id, 'email_domain', $_POST['email_domain'], true ); // <-- ONLY UPDATING ONCE
    }
    if ( isset($_POST['access_ids']) ) {
        $aid_checked = [];
        $access_ids = $_POST['access_ids'];
        foreach ($access_ids as $key=>$worth) {
            if ($worth == '1'){
                $aid_checked[] = $key;
            }
        }
        update_term_meta( $term_id, 'access_ids', $aid_checked );
    }
    if ( isset($_POST['facilitators']) ) {
        $fac_checked = [];
        $facilitators = $_POST['facilitators'];
        foreach ($facilitators as $key=>$worth) {
            if ($worth == '1'){
                $fac_checked[] = $key;
            }
        }
        update_term_meta( $term_id, 'facilitators', $fac_checked );
    }
}

Curiously sufficient my checkbox fields are updating high quality each single time, so one thing is occurring with the textual content fields.