Scheduling posts to update once per day with wp_cron

This is a typical example of an X-Y problem. Your cron is fine. Your logic not so.

You have a function that hooks into save_posts and you think that passing the array $update = array( 'ID' => get_the_ID() ) will trigger the action and so your post will update the taxonomy. That’s incorrect, unfortunately.

Passing this type of array (only the ID field) to wp_update_post will only identify the post, it has no data to save elsewhere in the array. So it won’t update anything and won’t trigger any save_post actions.

So your cron is running every day, but doing nothing.

Solution:

The function that hooks into save_post probably accept a post_id as param and update post if needed, right. So, instead of running wp_update_post and letting it update the post, call your function by itself.

while ($query->have_posts()) {
  $query->the_post();
  $toupdate = get_the_ID();

  your_function_that_hook_into_save_post( $toupdate );

}

Leave a Comment