最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

session - Trying to configure cron to get next value from array on each run

programmeradmin0浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论