いつもお世話になっております。
表題の件、Wordpressプラグイン「Post Expirator」等の自動削除プラグインを使用せずに実現したいと考えています。
下書きにする日は、Wordpressプラグイン「Smart Custom Fields」の日付ピッカーで指定しています。
下記コードだと、管理画面ログイン時に条件に一致すれば下書きに更新されるのですが、ログインしなくても自動で更新させたいです。
<?php $args = array( 'post_type' => 'news', 'posts_per_page' => 1, 'order' => 'DESC' ); $articles = new WP_Query( $args ); if ( $articles -> have_posts() ) : while( $articles -> have_posts() ): $articles -> the_post(); if ( strtotime( date( 'Y-m-d' ) ) >= strtotime( SCF::get( 'end-date' ) ) ) { wp_update_post( array( 'post_status' => 'draft' ) ); } ?> <div><?php the_title(); ?></div> <?php endwhile; else: ?> <div>記事がありません</div> <?php endif; ?>
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/02/17 10:23