Faking the “onSave” event

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!

Related posts

Leave a Reply

2 comments

  1. 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!';
    
  2. 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.