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' );
wp_schedule_single_event
? Specifically the 3rd argument it takes. Also you should use a taxonomy term not a post meta field if you're going to do a meta query. Searching for the jobs that are featured will become a very expensive and slow query to run if you use ameta_query
, and it will get progressively slower as the site gets larger very quicklywp_schedule_single_event( time() + 3600, 'job_featured_expire', $job_id );
Well, in this way still didn't change the post's meta value to 0.