I have some scheduled events in my WordPress site. For that I use a cron job, so it has created an option in the wp_options
table.
After some days, my site is getting slow. When I check my database, it has more than 2MB of data in the cron field, so I am thinking to clean it now. Will that affect my site's cron operations?
I guess it's all about entries in the table. Due to the fuzzy entries, my site is getting slow down. Here my code.
wp_schedule_event(time(), 'daily', 'kv_daily_post_expire_check');
function kv_daily_post_expire_check() {
$the_query = get_posts( 'post_type=job&post_status=publish' );
foreach($the_query as $single_post) {
$id=$single_post->ID;
$ad_close_date=get_post_meta($id, 'ad_close_date', true );
if($ad_close_date!=''){
$today=date("Y-m-d");
$ad_less_close_date=$ad_close_date-3;
if($ad_close_date<$today){
$update_post = array(
'ID' => $id,
'post_status' => 'expired',
'post_type' => 'job' );
wp_update_post($update_post);
}
else if($ad_less_close_date==$today){
$update_post = array(
'ID' => $id,
'post_status' => 'expired',
'post_type' => 'job' );
//wp_update_post($update_post);
kv_author_post_expiring_soon($id,3);
}
}
}
}
and here is the data which is there in my database table.
a:7:{i:1447098349;a:3:{s:16:"wp_version_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}s:17:"wp_update_plugins";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}s:16:"wp_update_themes";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}}i:1447099020;a:1:{s:20:"wp_maybe_auto_update";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:10:"twicedaily";s:4:"args";a:0:{}s:8:"interval";i:43200;}}}i:1447141549;a:1:{s:26:"kv_daily_post_expire_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:5:"daily";s:4:"args";a:0:{}s:8:"interval";i:86400;}}}i:1447141669;a:1:{s:26:"kv_daily_post_expire_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:5:"daily";s:4:"args";a:0:{}s:8:"interval";i:86400;}}}i:1447141790;a:1:{s:26:"kv_daily_post_expire_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:5:"daily";s:4:"args";a:0:{}s:8:"interval";i:86400;}}}i:1447141909;a:1:{s:26:"kv_daily_post_expire_check";a:1:{s:32:"40cd750bba9870f18aada2478b24840a";a:3:{s:8:"schedule";s:5:"daily";s:4:"args";a:0:{}s:8:"interval";i:86400;}}}s:7:"version";i:2;}
wp_schedule_event()
on every page load but it should be done only on plugin activation and cleared on plugin deactivation, otherwise you add a new cron on every page load. Things like that make people talk very bad about wp-cron performance when actually the problem is in their hands. And yes, clearing the cron row in database can make crons registered by other plugins to not exist anymore if they are registered on plugin activation as recommended. – cybmeta Nov 21 '15 at 8:15