最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Scheduling update post daily

programmeradmin0浏览0评论

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);
        }
    }
}
发布评论

评论列表(0)

  1. 暂无评论