我想要一些代码可以放在我的functions.php
仅修改指定自定义帖子类型的文件。
我已经尝试了几个插件,但它们都有比我需要的更多的功能。弄乱我不想让他们弄乱的东西太过分了。
理想情况下,代码将:
将每日cron作业设置为00:00(夜间)
有没有一个好的(简单的)插件可以做到这一点?你脑子里的一段代码片段?
我想要一些代码可以放在我的functions.php
仅修改指定自定义帖子类型的文件。
我已经尝试了几个插件,但它们都有比我需要的更多的功能。弄乱我不想让他们弄乱的东西太过分了。
理想情况下,代码将:
将每日cron作业设置为00:00(夜间)
有没有一个好的(简单的)插件可以做到这一点?你脑子里的一段代码片段?
add_action( \'wp\', \'delete_expired_coupons_daily\' );
function delete_expired_coupons_daily() {
if ( ! wp_next_scheduled( \'delete_expired_coupons\' ) ) {
wp_schedule_event( time(), \'daily\', \'delete_expired_coupons\');
}
}
add_action( \'delete_expired_coupons\', \'delete_expired_coupons_callback\' );
function delete_expired_coupons_callback() {
$args = array(
\'post_type\' => \'coupon\',
\'posts_per_page\' => -1
);
$coupons = new WP_Query($args);
if ($coupons->have_posts()):
while($coupons->have_posts()): $coupons->the_post();
// get the post publish date
$test = get_the_date();
// convert it to strto
$converter = strtotime($test);
// add 3 months to it
$deletedate = date(strtotime("+3 month", $converter));
// check if today is more than 3 months of publish date
if (time() > $deletedate) {
wp_delete_post(get_the_ID());
//Use wp_delete_post(get_the_ID(),true) to delete the post from the trash too.
}
endwhile;
endif;
}
将其放入函数中。php。从理论上讲,这将起到作用。复制自Posts to expire (deleted) after a date 并改变了对比。将增量更改为3分钟/秒,以便通过
$test = get_the_date(\'F j, Y G:i:s\');
$converter = strtotime($test);
$deletedate = date(strtotime("+3 minutes", $converter));
使用此插件进行测试。https://wordpress.org/plugins/trigger-scheduled-events/有两种方法可以做到这一点,我可以想到。。。
最简单的似乎是wp\\u cron命令。
http://codex.wordpress.org/Function_Reference/wp_cron
在您的函数中,您可以添加一些自定义SQL(或其他)来用您想要的任何内容更新您的数据库。。。或者,您可以尝试此插件http://wordpress.org/extend/plugins/wp-cron-control/让它成为你想要的。
我无法提供您所需的excact SQL,但使用这两个SQL,您应该能够在站点上运行计划的无人参与事件。
我有一个Wordpress网络,我的任务是禁用WP Cron并将其替换为Apache Cron。我已经设置了一个PHP脚本,当Apache Cron调用该脚本时,它将在网络下的所有站点中循环,并向该站点的wp Cron发出请求。php页面,从而执行其cron。我想使用Wordpress的瞬态特性来限制我的PHP脚本,因为Wordpress限制了自己的cron。然而,当我深入研究代码时,我看到doing\\u cron瞬态已设置(在cron.php#217中),但从未取消设置。瞬态是否一直未设置,或者Wor