I would like to run a daily cron job to update a field.
My code isn’t working, how can I do this?
//daily cron job
if ( ! wp_next_scheduled( ‘job_listing_cron_job’ ) ) {
wp_schedule_event( date( ‘Ymd’ ), ‘daily’, ‘job_listing_cron_job’ );
}
add_action( ‘job_listing_cron_job’, ‘update_random_number_t’ );
function update_random_number_t(){
$listings = new WP_Query(
array(
‘post_type’ => ‘therapist’,
‘post_status’ => ‘publish’
)
);
global $post;
if ($listings->have_posts()) {
while ($listings->have_post()) {
$listings->the_post();
$value = get_field(“feature_in_search”);
if (strpos($value, ‘es’) !== false) {
$random_value = rand(1, 100);
update_field(“field_58aebd8e060c0”, $random_value);
}else{
$random_value = rand(100, 600);
update_field(“field_58aebd8e060c0”, $random_value);
}
}
wp_reset_postdata();
}
}
function update_random_number() {
// do something every hour
global $post;
$args = array(
‘post_type’ => ‘therapist’
);
$listings = get_posts( $args );
foreach($listings as $post) : setup_postdata($post);
$value = get_field(“feature_in_search”);
if (strpos($value, ‘yes’) !== false) {
$random_value = rand(1, 100);
update_field(“field_58aebd8e060c0”, $random_value);
}else{
$random_value = rand(100, 600);