admin管理员组文章数量:1305910
I have created a function to change the post category to archive after expiry date. And it will update every time when I save a post.
But the question is that how can I schedule an update for posts daily. Otherwise, the post will show in the frontend with outdated information.
It would be great if anyone can help me. Thanks a lot!
// Archive post after expired
if ($expireTransient = get_transient($post->ID) === false) {
set_transient($post->ID, 'set for 1 minutes', 1 * MINUTE_IN_SECONDS );
$today = date('d/m/Y');
$args = array(
'post_type' => 'post',
'posts_per_page' => 200,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'end_date',
'value' => $today,
'compare' => '<='
)
)
);
$posts = get_posts($args);
foreach( $posts as $post ) {
if(get_field('end_date', $post->ID)) {
$postdata = array(
'ID' => $post->ID,
'post_category' => array(176)
);
wp_update_post($postdata);
}
}
}
本文标签: categoriesScheduling update post daily
版权声明:本文标题:categories - Scheduling update post daily 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741811091a2398799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论