I’m not away of any expired
post status, but you can set the post’s status to draft
of trash
.
First, you need to set up a cron job to run once in a while, and check if the date has come. Finding the proper time is up to you.
// Let's check the scheduled even on WP load
add_action( 'init', 'schedule_post_expiration' );
function schedule_post_expiration() {
// If the even is not scheduled already, then do schedule it
if ( ! wp_next_scheduled( 'reset-post-status' ) ) {
wp_schedule_event( strtotime( '00:00:00' ), 'daily', 'reset-post-status' );
}
}
// We hook our callback function to our custom action hook to run
// daily and update the post's status
add_action( 'reset-post-status', 'reset_post_status_callback' );
function reset_post_status_callback(){
// Get the current date
$date = date( 'Y-m-d' );
// Set the date we want to check. It should match the above date format.
$check_date="2018-02-11";
// Check if the time has come
if ( strtotime( $date ) > strtotime( $check_date ) ){
// Query a list of a specific author's posts
$author_args = array( 'author' => 123, 'post_status' => 'publish' );
// Do the query
$author_query = new WP_Query( $author_args );
// Check if the query has any post, and setup the post data
if ( $author_query->have_posts() ) {
while ( $author_query->have_posts() {
$author_query->the_post();
// Update the post's status
wp_update_post( array( 'ID' => get_the_ID(), 'post_status' => 'trash' ) );
}
}
// Reset the posts data
wp_reset_postdata();
}
}