Support

Account

Home Forums General Issues Update_field() don't work correctly with terms Reply To: Update_field() don't work correctly with terms

  • You are setting a custom field on a term. For this you need to include the taxonomy as part of the $post_id. I have altered the update_field() call of your code

    
    function my_create($term_id, $tt_id, $taxonomy) {
      // gets term_data for Post
      $term = get_term($term_id, 'interpret');
      // Create the Post and Save ID to $post_id
      $post = array(
          'post_title' => $term->name,
          'post_content' => $term->slug,
      );
      $post_id = wp_insert_post($post);
      // if Post was created
      if ($post_id) {
        // get Post by ID
        $link_to = get_post($post_id);
        // Post->ID
        $link = $link_to->ID;
        update_field('field_558e8544d5660', $link, 'interpret_'.$term_id);
      }
    }