admin管理员组文章数量:1391951
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
1 Answer
Reset to default 0Check 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.
本文标签: Server cron job not working
版权声明:本文标题:Server cron job not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744678410a2619252.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论