我的问题是-我有一个CPT Post name公司(CF Value-Google)和一个名为Role(CF V-Engineer)的页面。所以我想自动更新发布时间和日期company post 和Role page 如果发布的post自定义字段值与Google和Engineer匹配。
例如-
2021 9月13日晚上11:30:21发布的一篇招聘帖子有两个自定义字段“公司”和“角色”,其中包含谷歌和工程师的价值观。
已发布CPT Post公司有一篇帖子Google Jobs 其CF值与谷歌相似。
类似的已发布页面Engineer Jobs 拥有CF价值工程师。
所以我的所有条件都满足了,因为CF值匹配,现在代码应该用最近发布的发布日期和时间更新工程师工作(第页)、谷歌工作(发布)日期和时间。
任何参考代码或帮助都将不胜感激,我希望在functions.php 文件
我的代码(不工作)
function my_cron_schedules($schedules){
if(!isset($schedules["5min"])){
$schedules["5min"] = array(
\'interval\' => 1*60,
\'display\' => __(\'Once every 5 minutes\'));
}
if(!isset($schedules["30min"])){
$schedules["30min"] = array(
\'interval\' => 30*60,
\'display\' => __(\'Once every 30 minutes\'));
}
return $schedules;
}
add_filter(\'cron_schedules\',\'my_cron_schedules\');
wp_schedule_event(time(), \'5min\', \'my_hourly_event\', $args);
//add_action(\'init\',\'my_hourly_event\');
function my_hourly_event() {
$the_query = get_posts( \'post_type=post\' );
foreach($the_query as $single_post) {
$id=$single_post->ID;
$ad_close_date=get_post_meta($id, \'Validdate\', true );
if($ad_close_date!=\'\'){
$today=date("j F Y");
if($ad_close_date<$today){
$update_post = array(
\'ID\' => $id,
\'meta_key\' => \'Location\',
\'publish_date\' => get_the_time( \'\', $post->ID ),
\'post_type\' => \'jobs\',
\'meta_value\' => get_post_meta(get_the_ID(), \'Location\',true));
wp_update_post($update_post);
}
}
}
}