Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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 Aug 8 '12 at 2:31
    
See my comment below - may be a good work-around for you as well :) –  Zach Aug 9 '12 at 12:36

1 Answer 1

up vote 2 down vote accepted

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!';
share|improve this answer
    
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 Aug 9 '12 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 Aug 9 '12 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 Aug 9 '12 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 Aug 10 '12 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 Aug 10 '12 at 16:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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