title: Wordpress update field inside "set_object_terms" hook function
body: <p><strong>Bonjour!</strong></p>
  
  <p>I am trying to rewrite <a href="https://stackoverflow.com/questions/60079535/automatically-check-child-categories-terms-when-parent-category-is-checked">this</a> custom <code>set_object_terms</code> hook function.
  What I am trying to achieve in addition to <strong>Automatically check child categories/terms when parent category is checked</strong> as this function already is doing, is to also update the GeoDirectory field <code>post_category</code> with the same data as the updated values for: <code>$categories = get_the_terms( $post-&gt;ID, 'gd_placecategory' );</code></p>
  
  <p>Note that Geo Directory has it own set of get/delete/save functions, I have tested them from a template . What I have tried in order to solve this issue is to create an <code>$merge</code> and <code>$diff</code> variable for add and remove, and then trying to add this to the <code>post_category</code> field by using the <code>geodir_save_post_meta()</code> function. I have also tried to perform the update by using the <code>$wpdb-&gt;update()</code> as well. </p>
  
  <pre><code>        .
          .
          .
          .
  
  
  // Any terms ADDED this time?
  if( !empty($added_terms) ){
      $add = array();
  
      foreach( $added_terms as $added_term ){
  
          // Do any of these added terms have children?
          if( $added_child_terms = get_term_children( $added_term, $taxonomy ) ){
              // Append those children
              wp_set_object_terms( $object_id, $added_child_terms, $taxonomy, true );
              $add[] = $added_child_terms;
          }
      }
  
      if( !empty($add) ){
  
          $add = $add[0];
          $merge = array_merge($old_tt_ids,$add);  
          $merge = implode(",",$merge);
  
          if( !empty($merge) ){
  
              geodir_save_post_meta($object_id, 'post_category', $merge);
              //$wpdb-&gt;update( 'wp_geodir_gd_subscription_detail', array( 'post_category' =&gt; $merge), array('post_id' =&gt; $object_id ));
  
          }
      }
  }
  
  // Any terms REMOVED?
  if( !empty($removed_terms) ){
       $remove = array();
  
      foreach( $removed_terms as $removed_terms ){
  
          // Do any of the removed terms have children?
          if( $removed_child_terms = get_term_children( $removed_terms, $taxonomy ) ){
              // Remove them all
              wp_remove_object_terms( $object_id, $removed_child_terms, $taxonomy, true );
              $remove[] = $removed_child_terms;
          }
      }
  
      if( !empty($remove) ){
  
          $remove = $remove[0];    
          $diff = array_diff($old_tt_ids,$remove);  
          $diff = implode(",",$diff);
  
          if( !empty($diff) ){
  
              geodir_save_post_meta($object_id, 'post_category', $diff );
              //$wpdb-&gt;update( 'wp_geodir_gd_subscription_detail', array( 'post_category' =&gt; $diff), array('post_id' =&gt; $object_id ));
  
          }
      }
  
  }
  </code></pre>
  
  <p>When either the <code>geodir_save_post_meta()</code> function or the <code>$wpdb-&gt;update()</code> is added to the function, this custom function does run, but only the terms are changed. None of the <code>set_object_terms</code> generated terms is added to the <code>post_category</code> field.  </p>
  
  <p>It seems to me that the <code>set_object_terms</code> hook is not the place to run a update from. Still I need this hook to perform the <strong>Automatically check child categories/terms when parent category is checked</strong>.</p>
  
  <p>How can I both <strong>Automatically check child categories/terms when parent category is checked</strong> and update the GeoDirectory field <code>post_category</code> at the same time?</p>