Title: Do not replace with empty element value
Last modified: April 19, 2020

---

# Do not replace with empty element value

 *  Resolved [Samantha](https://wordpress.org/support/users/dydyt/)
 * (@dydyt)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/do-not-replace-with-empty-element-value/)
 * Hi there,
 * I can’t figure out how do not raplace existing post tags with a empty value.
 * For eaxample: I imported posts with the following json file:
 *     ```
       [
          {
             "name":"Kialeas",
             "tags":"red, blue, green"
          },
          {
             "name":"Orbital",
             "tags":"one, two, three"
          },
          {
             "name":"Manique",
             "tags":"cat, dog, pig"
          }
       ]   
       ```
   
 * Now i want to update with the following:
 *     ```
       [
          {
             "name":"Kialeas",
             "tags":"sky, moon, earth",
             "cat":"One"
          },
          {
             "name":"Orbital",
             "tags":"audi, bmw, merc",
             "cat":"Two"
          },
          {
             "name":"Manique",
             "tags":"",
             "cat":"Three"
          }
       ]  
       ```
   
 * If `"tags":""` is empty it will remove exiting post tags.
 * How to avoid it?
 * Thank you!
    -  This topic was modified 6 years, 1 month ago by [Samantha](https://wordpress.org/support/users/dydyt/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/do-not-replace-with-empty-element-value/#post-12747064)
 * Hi [@dydyt](https://wordpress.org/support/users/dydyt/)
 * To auto-detect that tags are missing and keep the existing ones on a per-record
   basis, you can write some custom code that uses our API: [https://www.wpallimport.com/documentation/advanced/action-reference/#wp_all_import_set_post_terms](https://www.wpallimport.com/documentation/advanced/action-reference/#wp_all_import_set_post_terms).
 * Here is an example snippet that you can modify for your use case (this shows 
   how to keep the “Featured” category in-tact even if it’s not in the import record):
 *     ```
       /**
        * Example: Leave assigned category "Featured" in tact, even if it's not included in the import.
        *
        */
   
       add_filter( 'wp_all_import_set_post_terms', 'wpai_wp_all_import_set_post_terms', 10, 4 );
   
       function wpai_wp_all_import_set_post_terms( $term_taxonomy_ids, $tx_name, $pid, $import_id ) {
               if ( $tx_name == 'product_cat' ){
                       $txes_list = get_the_terms($pid, $tx_name);
                       if ( ! empty($txes_list) ){
                               foreach ($txes_list as $cat){
                                       if ($cat->name == 'Featured'){
                                               $term_taxonomy_ids[] = $cat->term_taxonomy_id;
                                               break;
                                       } 
                               }
                       }
               }
               return $term_taxonomy_ids;
       }
       ```
   
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/do-not-replace-with-empty-element-value/#post-12790774)
 * Hi [@dydyt](https://wordpress.org/support/users/dydyt/)
 * I’m marking this as resolved since we haven’t heard back. You can respond here
   if you still have questions about this.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Do not replace with empty element value’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/do-not-replace-with-empty-element-value/#post-12790774)
 * Status: resolved