So I have this block of code and it is driving me crazy:
if ( ! wp_next_scheduled( 'change_quote_hook_short' ) ) {
wp_schedule_event( time(), 'one_minute', 'change_quote_hook_short' );
}
add_action( 'change_quote_hook_short', 'get_next' );
function get_next() {
$new_ar = array ('Ad1', 'Ad2', 'Ad3', 'Ad4', 'Ad5');
$id = ++$_SESSION['ad_id'] % count($new_ar);
$_SESSION['ad_id'] = $id;
$rsmid_single = $new_ar[$id];
update_option('rsmid_single', $rsmid_single);
}
On each run of the function get_next, when I check $rsmid_single variable it changes value correctly. Still, the option in the table is always set at Ad2. I have also checked, cron is working (when I switch value for $rsmid_single, it shows in the table after one minute). Like update_option is executed before increment finished. If you can please tell me if this is possible or should I search for some alternative approach?