首先,确保实际上有15分钟的可用时间间隔。
// create the cron scheduled interval to be used
add_filter(\'cron_schedules\',\'ex11_cron_schedules\');
function ex11_cron_schedules($schedules){
if(!isset($schedules["15min"])){
$schedules["15min"] = array(
\'interval\' => 15*60,
\'display\' => __(\'Once every 15 minutes\'));
}
return $schedules;
}
然后创建自定义WP\\U查询循环,以获取需要比较的所有记录,并归档不再需要的记录(副本):
// I haven\'t tested this yet. You might need to fine tune it.
// You might also need to tune the query statements to suit the Track CPT
function wpse_archive_duplicate_tracks(){
$args = array( \'post_type\'=>\'track\',\'pust_status\'=>\'publish\');
$tracks = get_posts($args);
$tracks_to_keep = array();
foreach($tracks as $track){
if (array_key_exists($track->artist . \'~\' .$track->post_title, $tracks_to_keep)){
$toUpdate = array(
\'ID\' = $track->ID,
\'post_status\' = \'archive\', // change to \'trash\' to delete
);
wp_update_post($toUpdate);
} else {
$tracks_to_keep[$track->artist . \'~\' .$track->post_title] = $track;
}
}
最后,您需要安排归档功能:
wp_schedule_event(time(), \'15min\', \'wpse_archive_duplicate_tracks\');
Parting thought: 您可能还想考虑在已检查的曲目中添加meta\\u数据字段,这样就不必每次都检查它们。但是如果副本可以随时返回,这可能不适合您的情况。
祝你好运