I know this question has been asked a few times but I can't find one with an adequate answer.
I need to run through all my posts and update them as in -> go to the edit screen a press Update - as some values for custom field values have been updated automatically.
Is there anyway of doing this automatically?
Running wp_update_post()
etc. does not do this. Nor does Bulk Edit update.
Any thoughts would be most appreciated.
Thanks, D.
I know this question has been asked a few times but I can't find one with an adequate answer.
I need to run through all my posts and update them as in -> go to the edit screen a press Update - as some values for custom field values have been updated automatically.
Is there anyway of doing this automatically?
Running wp_update_post()
etc. does not do this. Nor does Bulk Edit update.
Any thoughts would be most appreciated.
Thanks, D.
I would have preferred to put this as a comment, but space does not allow for it so sorry about that. It might help you rather than being an answer. I am using 'product', but it could just as easy be 'post'.
function update_all()
{
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
);
$products_array = get_posts($args);
if (!empty($products_array))
{
foreach ($products_array as $product)
{
echo "product : " . $product->ID;
//Update whatever here, eg wp_update_post($product->id,$error);
}
}
echo "</pre>";
}
As you have the product id for each product in a loop, you can get any meta or custom values for that product, and update them. I used this to bulk update prices for example. Obviously you would only want to run this from time to time, so I keep it remarked in the code. You could of course run it as a cron. I am a bit unclear on what you are trying to update. Looks to me like it's simply the publish date, which you could do in a loop.
I fail to see why wp_update_post in this loops wouldn't do it. Perhaps you need to enable displaying the errors when it runs.