来自一个类别的帖子几乎完全使用高级自定义域,它们包括来自自定义域的开始日期和结束日期。基本上,我想查询该特定类别(ICO)的所有帖子,看看预开始日期是否小于当前日期,移动类别x中的帖子,或者如果开始日期小于当前日期,则将其移动到类别y。我有2个开始日期和2个结束日期通过ACF中的重复字段。这些帖子是项目,它们有一个"pre“开始日期和一个正常的开始日期,两者都有结束日期。
到目前为止,我做到了这一点,但我不确定这是不是最好的解决方案,这就是为什么我求助于你们专业人士:)
<?php
$args = array(
'numberposts' => -1,
'cat' => 13,
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'ico',
);
$the_query = new WP_Query( $args );
$posts = $the_query->posts;
foreach($posts as $post) {
$the_id = get_the_ID();
$curtime = date('d-m-Y');
$content = get_field('overview', $the_id);
if($content):
foreach ($content as $key => $content):
$start_date = $content['ico_time_start'];
$end_date = $content['ico_time_end'];
$prestart_date = $content['pre_ico_time_start'];
$preend_date = $content['pre_ico_time_end'];
endforeach;
endif;
$newicoDate = date("d-m-Y", strtotime($end_date));
$newpreicoDate = date("d-m-Y", strtotime($preend_date));
$currenttime = new DateTime($curtime);
$icoEnd = new DateTime($newicoDate);
$preicoEnd = new DateTime($newpreicoDate);
if ($preicoEnd < $currenttime) : wp_set_post_categories( $the_id, array( 13, 15 ) ); endif;
if ($icoEnd < $currenttime) : wp_set_post_categories( $the_id, array( 13, 16 ) ); endif;
}
?>
我希望能够启动这个作为cron (而不是wp cron)每天一次或两次,以检查所有的类别,并移动他们,如果需要的话。
发布于 2018-08-07 15:05:54
像这样的东西在你的情况下是可行的。
# crontab -e
00 * * * * /usr/local/bin/php /home/user/yourscript.php
首先从Linux命令行问题
crontab -e
在第一行中,输入以下内容
00 * * * * /usr/local/bin/php /home/user/yourscript.php
第一组数字表示cron作业的时间。
https://stackoverflow.com/questions/51727962
复制相似问题