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?
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!