admin管理员组

文章数量:1323715

I want to pass the $job_id variable to the expire_job_featured function (for wp single cron event) but I don't know how can I do that.

This is the full code of setting job's post meta value "featured" to 1 and then I want to schedule a single cron event to make the "featured" meta value to 0 after an hour. But I can't pass the $job_id variable to the expire_job_feature function.

    add_action( 'init', function() {
    $job_id = filter_input( INPUT_GET, 'feature_job', FILTER_VALIDATE_INT );

    if ( null === $job_id ) {
        return;
    }

    update_post_meta( $job_id, 'featured', 1 );
    wp_schedule_single_event( time() + 3600, 'job_featured_expire' );
    
});

function expire_job_featured($job_id) {
   update_post_meta( $job_id, 'featured', 0 );
}
add_action( 'job_featured_expire','expire_job_featured' );

本文标签: cronHow to pass variable from other function