• Resolved George

    (@quantum_leap)


    I was wondering what is the best way for importing ACF data. I will be creating custom post types, custom fields, options, etc. ACF has a Tools menu where you can export everything in a json file. I imagine, I would need to use the after_import action to import that json file somehow? If I need to contact the ACF devs, what should I ask them? Would a possible solution be to check the ACF code and see how the ACF export file is being imported and integrate that code inside my theme’s after_import function?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there @quantum_leap,

    Thanks for reaching out! Using after_import is the way to go. You may need to consult the ACF devs about this since we don’t know as much about it as they do, but you’ll likely need to write custom code to import the JSON file using methods built into ACF. I found some old posts that discuss how to import ACF JSON data programmatically, but given that these posts are a few years old and may be out of date, the best thing to do would be to contact ACF support.

    In case it helps, you can show them this guide on our site so they have a better idea of what you’re trying to accomplish through our plugin:

    https://ocdi.com/advanced-integration-guide/#after-import-custom-code-execution

    I hope that helps! Have a great day!

    Thread Starter George

    (@quantum_leap)

    Hmmm….I made it work, I constructed a script that imports the JSON ACF file with the ocdi/after_import hook. I had to reregister the custom post type inside the ocdi/before_content_import hook since the xml that was imported probably didn’t “see” any CPT created at that stage. Does that sound a recommended thing to do, or is there any other more optimized solution?

    Hi there @quantum_leap,

    The importer ignores any CPT import items that are not already registered to on the site when it runs. So for example, if you have WooCommerce products in the import files, but WooCommerce itself is not active, those items get skipped. This is why we recommend activating the plugins you’ll be using before importing content.

    Because you’re using a CPT not registered by a plugin, you have to register it yourself before the import runs. Using before_content_import is the way to go, so you’re doing everything the right way. 🙂

    I hope that helps! Have a great day!

    Thread Starter George

    (@quantum_leap)

    Erh, hold on a minute! I was under the impression that the demo content was always imported after all required or not plugins were installed AND activated, is that not the case? The CPT was created with ACF so I would prefer for ACF to be activated before the content is imported so that I won’t have to register the CPT twice! All this time, I was under the impression that installed plugins were activated BEFORE the demo import was initiated.

    • This reply was modified 1 year, 3 months ago by George.

    Hi there @quantum_leap,

    The problem comes down to when ACF registers those CPTs. Plugins need to be activated before the import is run so that way they exist within WordPress when their data is imported.

    In the case of ACF, if the CPT is not fully registered before the import runs, the items for it will be skipped. So, if you’re running the import and the CPTs from ACF are getting skipped, it’s because they are registered after the import runs. That’s why you would need to hook into ocdi/before_content_import.

    I hope that helps!

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

The topic ‘ACF integration’ is closed to new replies.