Save all posts automatically and execute function
-
Hi everybody,
I have a database with a custom post type “person” with thousands of pages. Each person’s age is calculated using a custom field (e.g. 1964-02-15) and is then stored as a taxonomy term, when the post is saved (I need the age as taxonomy).
That works correct with this code in my functions.php:
function calculate_age($post_id) { //...code to calculate the age of the person... wp_set_object_terms( $post_id, $interval, 'age'); } add_action('save_post','calculate_age',100, 2); }
In order to keep the age up to date now, I would like to have the posts automatically saved overnight, so that the taxonomy term is always correct. I know there is a WordPress cron function, to do things automatically. But how can I save all posts of my custom post type to execute the above function? I’ve tried various code snippets I found on the web (wp_schedule_event, register_activation_hook, wp_update_post etc.) but it seems, I’m just messing up the correct way to do it.
I would be very happy, if someone could tell me how to do it step by step 🙂
Thank you very much in advance!
Andreas
- The topic ‘Save all posts automatically and execute function’ is closed to new replies.