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

Server cron job not working

programmeradmin0浏览0评论

I want to setup server cron job for my WordPress website. This is what I have done so far.
I added this line to my wp-config file.

define('DISABLE_WP_CRON', true);

I added this command for setting up cron job.

wget -q -O - .php?doing_wp_cron >/dev/null 2>&1

But my cron function is not working. I setup cron and php function on staging site in a same way and it is working on staging site which is on a different host.
This live website is on bluehost and its default emails are firing as I remove >/dev/null 2>&1 from my command for testing purpose but this PHP function is not working.
Here is my code in functions.php file which is working on staging site but not on live site.

function my_cron_schedules($schedules){
  if(!isset($schedules["30min"])){
    $schedules["30min"] = array(
    'interval' => 30*60,
    'display' => __('Once every 30 minutes'));
  }
  return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');


function schedule_my_cron(){
  // Schedules the event if it's NOT already scheduled.
  if ( ! wp_next_scheduled ( 'my_30min_event' ) ) {
     wp_schedule_event( time(), '30min', 'my_30min_event' );
  }
}
add_action( 'init', 'schedule_my_cron' );


add_action( 'my_30min_event', 'job_expiration_schedule_hook' );
function job_expiration_schedule_hook() {
$loop = new WP_Query( array( 'post_type' => 'job_listing', 'posts_per_page' => 10, 'post_status' => 'publish') );
 if ( $loop->have_posts() ) :
    while ( $loop->have_posts() ) : $loop->the_post();
    $ID = get_the_ID();

    $job_post_meta = get_post_meta($ID, '_job_expires', true);
    if ( !metadata_exists( 'job_listing', $ID, '_job_expires' ) || empty($job_post_meta)) {
        $job_published_date = get_the_time("Y-m-d", $ID);
        $expire_date = date('Y-m-d', strtotime($job_published_date. ' + 60 days'));
        update_post_meta($ID, '_job_expires', $expire_date);
    }

    endwhile;
endif;
}

I want to setup server cron job for my WordPress website. This is what I have done so far.
I added this line to my wp-config file.

define('DISABLE_WP_CRON', true);

I added this command for setting up cron job.

wget -q -O - https://example/wp-cron.php?doing_wp_cron >/dev/null 2>&1

But my cron function is not working. I setup cron and php function on staging site in a same way and it is working on staging site which is on a different host.
This live website is on bluehost and its default emails are firing as I remove >/dev/null 2>&1 from my command for testing purpose but this PHP function is not working.
Here is my code in functions.php file which is working on staging site but not on live site.

function my_cron_schedules($schedules){
  if(!isset($schedules["30min"])){
    $schedules["30min"] = array(
    'interval' => 30*60,
    'display' => __('Once every 30 minutes'));
  }
  return $schedules;
}
add_filter('cron_schedules','my_cron_schedules');


function schedule_my_cron(){
  // Schedules the event if it's NOT already scheduled.
  if ( ! wp_next_scheduled ( 'my_30min_event' ) ) {
     wp_schedule_event( time(), '30min', 'my_30min_event' );
  }
}
add_action( 'init', 'schedule_my_cron' );


add_action( 'my_30min_event', 'job_expiration_schedule_hook' );
function job_expiration_schedule_hook() {
$loop = new WP_Query( array( 'post_type' => 'job_listing', 'posts_per_page' => 10, 'post_status' => 'publish') );
 if ( $loop->have_posts() ) :
    while ( $loop->have_posts() ) : $loop->the_post();
    $ID = get_the_ID();

    $job_post_meta = get_post_meta($ID, '_job_expires', true);
    if ( !metadata_exists( 'job_listing', $ID, '_job_expires' ) || empty($job_post_meta)) {
        $job_published_date = get_the_time("Y-m-d", $ID);
        $expire_date = date('Y-m-d', strtotime($job_published_date. ' + 60 days'));
        update_post_meta($ID, '_job_expires', $expire_date);
    }

    endwhile;
endif;
}
Share Improve this question asked Dec 29, 2019 at 22:11 wplearnerwplearner 4892 gold badges9 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Check cache is disabled on live, then try.

This is 99% likely a cache issue.

If it was the other way around it would likely point to a FQDN issue whereby the domain does not resolve and you would need to modify host files.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论