1

While a specific use-case, I believe this may benefit others.

I am using TurboCSV to mass-import a number of posts into WordPress (which it is doing wonderfully so far). Within that import, I am specifying custom fields to be used in conjunction with Advanced Custom Fields to store/output the data. The post_meta table is being created correctly, but the part that is not working as expected is generating ACF's hidden fields (which work with field relationships). When the import is first done, those database tables are not created until you manually go into each post and re-save them. I was wondering if there is a way to "fake" the onSave event for WordPress for a number of posts. ACF also passes along post information (stored on the post edit screen) to this save function - which makes it a bit trickier - but I'd be interested if anyone has any thoughts. Thanks!

2
  • Gosh -- I was hoping someone would've answered this question. Did you ever come up with a solution yourself? I can't tell you how many times I've needed to go into every custom post type on my site and simply re-save them to reformat some ACF data that I've changed the structure of. It would seem like there'd HAVE to be a way to automate this.. (BTW, odd, but I realized I just started following you on Twitter the other day, and here we are wondering about the same problem. Kismet! )
    – user19035
    Commented Aug 8, 2012 at 2:31
  • See my comment below - may be a good work-around for you as well :)
    – Zach
    Commented Aug 9, 2012 at 12:36

2 Answers 2

2

Have you seen wpshell? It's a command line tool for wordpress. Basically, it's a Wordpress environment that lets you run arbitrary php - so you could set up a WP_Query that pulls all posts, loop through them, and fire that command on each one.

Sort of what I had in mind, untested. Using wp_update_post() as it contains the save_post hook, and is the equivalent of hitting 'update' on the post edit screen:

$args = array('posts_per_page' => -1, 'post_type' => 'any')
$query = new Wp_query($args)
while ( $query->have_posts() ) : $query->the_post();
    $post->wp_update_post();
    echo $post->ID . '<br />';
endwhile;
echo 'Done!  Everything saved!';
6
  • Ah very interesting. One possible workaround I think will work (while still a bit time consuming), is to use fakeapp.com What I can do there is create a repeating action in FakeApp that runs through each post ID (that I specify from the range that is imported) and then does the saving on each one. I can then take a nap while it does the work for me ;)
    – Zach
    Commented Aug 9, 2012 at 12:31
  • I don't see how that's quicker or easier than using an automated tool built for WordPress, but to each their own.
    – SickHippie
    Commented Aug 9, 2012 at 23:18
  • 1
    No I definitely agree - was just offering up what I had found thusfar. I'll definitely give wpshell a shot. Thanks!
    – Zach
    Commented Aug 9, 2012 at 23:54
  • No problem - you could also put this code into a template file and run from there. Create a page /resave (with the slug resave), make a copy of page.php called page-resave.php put this code in place of the loop, and load that page. You should see it iterate through a list of post numbers (it will skip revisions and CPT's that are marked exclude_from_search). And THAT would be quick and easy. :)
    – SickHippie
    Commented Aug 10, 2012 at 16:39
  • Awesome! Now let's say that when the post is saved, it uses $POST data to write to the hidden fields stored in the database (that's how Advanced Custom Fields does it), does wp_update_post() simulate that data? That's the only reason I was going the "Fake App" way to ensure that information was there.
    – Zach
    Commented Aug 10, 2012 at 16:42
1

I know this is an old ticket, but data importing is an ongoing challenge for users, I am sure!

I've recently started using WP All Import, and I came across the same problem with ACF fields. Luckily, they came out with an extension for the plugin for exactly this problem:

http://www.wpallimport.com/add-ons/

WP All Import ACF Add-On should handle this conundrum no problem. It is a premium plugin, but I use it almost monthly, so it has more than paid for itself. Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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