Working code:
add_action( 'acf/save_post', 'fritlaeg_artikel_3m' );
function fritlaeg_artikel_3m( $post_id ) {
if( get_post_meta( $post_id, 'fritlaeg_artikel_i_3_maneder', true ) ) {
// Getting a UNIX Timestamp
$timestamp = time();
// Using WordPress Time Constants
// https://codex.wordpress.org/Easier_Expression_of_Time_Constants
$timestamp_after_hour = $timestamp + 0.5 * MINUTE_IN_SECONDS;
// Define remaining parameters
$args = array( $post_id );
$hook = 'fritlaegning_clear_meta_data';
// Get the timestmap of an already scheduled event for the same post and the same event action ($hook)
// Returns false if it is not scheduled
$scheduled_timestamp = wp_next_scheduled( $hook, $args );
if( $scheduled_timestamp == false ) {
wp_schedule_single_event( $timestamp_after_hour, $hook, $args );
}
}
}
/* Clear the database metadata when cron event fires */
add_action( 'fritlaegning_clear_meta_data', 'process_clear_meta_data' );
function process_clear_meta_data( $post_id ) {
update_post_meta( $post_id, 'fritlaeg_artikel_i_3_maneder', '0' );
}