You’ll need two meta fields: the ‘available’ field, and a ‘lastchecked’ field that contains a Unix timestamp for when the box was checked.
Then, you can use wp_cron (assuming your site has enough traffic; but most sites will get at least one visit an hour; if not, you can always set up a regular cron to visit your site every hour) to run your reset.
Assuming the meta fields are named as above, and ‘available’ is 1 for yes, 0 for no:
function reset_available_meta() {
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'lastchecked',
'value' => time() - ( 60 * 60 * 2 ), // 2 hours ago
'compare' => '<='
)
),
'posts_per_page' => -1
);
$resetQ = new WP_Query( $args );
while ( $resetQ->have_posts() ) {
$resetQ->the_post();
update_post_meta( get_the_ID(), 'available', '0' );
//optional: update lastchecked so it's not included for the next call
update_post_meta( get_the_ID(), 'lastchecked', time() );
}
}
wp_schedule_event(time(), 'hourly', 'reset_available_meta' );