I'm using ACF in my custom post type and I have 2 numeric fields: one for Birth year and another for Age. I want to update the age field automatically based on the birth year field value. I found out an acf filter that updates the field value before it is saved into the database and created the following function:
function update_acf_value_age( $value, $post_id, $field, $original ) {
$birth_year = get_field( 'birth_year', $post_id );
$value = date('Y') - $birth_year;
return $value;
}
add_filter('acf/update_value/name=age', 'update_acf_value_age', 10, 4);
It is working fine and updates the age value every time I save a certain post. But I need it to be updated every year, ideally automatically. Is there a way to automatically force every post to be saved/updated yearly? Or is there a better approach to what I'm trying to accomplish?
I read about something called WP-Cron but I don't understand how to implement it and don't know if it's a good solution for this case.
Thanks in advance!