0

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 May 24 '17 at 23:26
  • No, it's fresh installation – raaaa May 25 '17 at 8:49
1
+50

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).

or

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

or

(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. – fxuser Jul 16 '17 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 Jul 16 '17 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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