I'm using WP import/export function. In exported XML file term_id is 4, but it becomes random number after import which is breaking my widgets structure. Is there any way to force or keep old term_id when importing to new website?

  • Are you importing into a site that already has content?
    – Milo
    Commented May 24, 2017 at 23:26
  • No, it's fresh installation
    – raaaa
    Commented May 25, 2017 at 8:49

1 Answer 1


Off the top of my head, you'd have to either:

(a) bypass the import functionality in WP and do it direct to the database, so the term IDs stay the same (i.e. export/import from phpMySQL).


(b) write a "run once" data migration function to update your term IDs once they're imported, using a reference table.


(c) change your plugin/widget to detect the term slug or name instead of the ID.

I believe the last of those would be "best practice", as it ensures your plugin works regardless of the data in the back end. Using the visible/accessible parts of the data is always better, even if it's harder, longer and/or stupidly difficult with WP's available functions!

  • The reason this happens in my case is because a term with ID=9 exists for a custom post type but when i install my theme , woocommerce adds some term entries with an ID=9 and later when i import the demo data this ID is no longer for my custom post type and gets added with another ID. I think your (c) option is the best to follow.
    – stergosz
    Commented Jul 16, 2017 at 10:10
  • Did a quick search. You'll need to find your widget check for ID=9 and use get_term_by to get the ID first: codex.wordpress.org/Function_Reference/get_term_by
    – Spike
    Commented Jul 16, 2017 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.