ACF Failing

Closed

Import WP Addon - Advanced Custom Fields Updated 6 months ago 15 Replies

Art asked 6 months ago on May 15, 2024 at 6:00 pm

When I try to run the import on my ACF fields, and I try to access the fields via the ACF function \”get_fields()\”, I don\’t get the filed list back I just get a \”false\” response.  However, if I create a CPT entry using the regular ACF form, it works fine.  This happens whether I use the \”text\” option or not on the fields.  It\’s like there is something else breaking this because the actual data looks fine in the database, and if I open the item up in the form, everything looks okay… however I have some automated tasks I need to run on the data but I cannot because of this issue.

J

James replied Support Agent

6 months ago on May 15, 2024 at 6:29 pm

Hi Art,

Can you please export and attach your importer settings to this ticket so i can see your setup, by going to Tools > Import WP > Settings / Tools > Import / Export and select and export your importer as a JSON file.

James

AS

Art replied privately

6 months ago on May 15, 2024 at 6:59 pm

AS

Art replied

6 months ago on May 15, 2024 at 7:05 pm

For what it's worth, I am also getting an odd behavior where the entry is being assigned a CPT category for no obvious reason.  The custom code I am using is intended to assign certain CPT categories, but when I get this error I exit the function before it has a chance to do anything. 

 

I also did try marking most of my other plugins in the compatibility page but the behavior does not change.

J

James replied Support Agent

6 months ago on May 15, 2024 at 7:10 pm

Can you send me a screenshot of the compatibility page, the version numbers of all importwp and importwp  plugins installed, and possibly your acf field group export via ACF > tools

AS

Art replied privately

6 months ago on May 15, 2024 at 7:26 pm

J

James replied Support Agent

6 months ago on May 15, 2024 at 7:52 pm

Thanks, everything looks fine, last thing can you send either the csv file, or the csv with just the first 3 rows in it that you have used in the import.

J

James replied privately Support Agent

6 months ago on May 15, 2024 at 8:09 pm

AS

Art replied privately

6 months ago on May 15, 2024 at 8:33 pm

AS

Art replied privately

6 months ago on May 15, 2024 at 8:40 pm

J

James replied Support Agent

6 months ago on May 15, 2024 at 8:54 pm

So importing from your csv file, and using the get_fields() acf function on each, i have attached the import history, code, and output.

What happens if you add the following code, replacing the ids with your imported 3 records

add_action('init', function () {

    if (!isset($_GET['dev'])) {
        return;
    }

    print_r(get_fields(65));
    print_r(get_fields(66));
    print_r(get_fields(67));

    die();
});

Then accessing it via: http://your.site/?dev

AS

Art replied

6 months ago on May 15, 2024 at 9:30 pm

I get the results I expect.  I suspect now that this is a timing issue.  I am using the hook 'wp_after_insert_post' to do my work, which works fine from the WP editor, but I'm wondering if with your software in the mix if I should instead run this using a different (additional) hook?

AS

Art replied

6 months ago on May 15, 2024 at 9:31 pm

And by the way, I did add the post_id which is passed to the hook (and is present) to the get_fields function with the same zero result in my code.

J

James replied Support Agent

6 months ago on May 15, 2024 at 9:54 pm

I think your suggestion is correct, when you create a record with acf fields via the wordpress UI, it all happens at the same time, however in the importer it is slightly staggered.

To get around this i would recommend trying the following code (change 1930 to the id of your importer, so not to target every importer, and add your code inside the isInsert if statement):

add_action('iwp/importer/mapper/after', function ($data) {

    if (iwp()->importer->getId() != 1930) {
        return;
    }

    /**
     * @var \ImportWP\Common\Importer\ParsedData $data
     */
    if ($data->isInsert()) {
        $id = $data->getId();

        $acf_fields = get_fields($id);
    }
});

 

AS

Art replied

6 months ago on May 15, 2024 at 11:48 pm

Thanks, I think that is helpful but I will have to test later.  I did work out that I could run the function as much as I wanted to I did the import and then ran a loop over the list of post_ids and that worked for a one time thing... I will test your solution later though because I will want this to be as handsoff in the long run as possible.

Thanks!

Art

J

James replied Support Agent

6 months ago on May 16, 2024 at 7:55 am

You could instead use the acf/update_value filter or the acf/save_post action hooks