Home Forums General Issues ACF wp all import add on – How to delete? Reply To: ACF wp all import add on – How to delete?

  • So your filter basically runs multiple times for each product post for each row of the import that matches that post.

    There is no way to do this in a single function call.

    You will need to track a list of every row that is imported and this list of data will need to be updated each time your filter is run.

    Do to the way that WPAI works, this information will need to be stored in a session variable because WPAI may or may not import every row in a single request and this is the only way to compile a list of everything during a single import.

    An alternative session to this would be two write all of the data out to a temporary file on the server and then load updated and re-save that file every time your filter runs, basically duplicating what a PHP session does.

    The data could be as simple as an array something like

    $data = array(
       $post_id => (
         // list of row indexes updated or added

    With this compiled list of data created you would then add a WPAI pmxi_after_xml_import action. This runs after the import is complete and then in this action you can look at your compiled list of rows that were imported and compare them to the rows for each post ID and then delete the missing ones. Basically to do this you would get the repeater for each post again and then look to see what rows should be kept and delete the rest.

    On top of this you also need to keep in mind that when deleting rows from an ACF repeater you must go in descending index order to make sure you delete the correct rows. For example let’s say that you need to delete rows 1 & 2. If you delete 1 first, then 2 becomes 1 and 3 becomes 2 and when you attempt to delete row 2 you’ll actually be deleting what was row 3.

    To make matters worse, none of this may work. This solution would not be scalable. Updating many products, hundreds or thousands, would likely cause a server timeout during the delete process unless certain precautions are taken. This would depend on your hosting environment and what your hosting company allows, like extending the amount of time the server is allowed to process and possibly preventing the browser from timing on the AJAX request. The latter may not even be possible.

    Overall this is several hours or more of R&D work and you’ll need to find a developer if you can’t do it. You might want to look into hiring a freelancer.