When I create a post in WordPress, I determine an expiration date through a plugin called Post Expirator . My question is how I can delete these posts from the home page , categories and the like when they expire.
In addition , I would make all expired posts were displayed at a certain point of my site .
I have tried using the meta_keys and meta_value , but I’m not succeeding.
<?php $args = array(
'meta_key' => '_expiration-date',
);
$query = new WP_Query( $args ); ?>
<?php if($query->have_posts()) : ?>
<?php while($query->have_posts()) : $query->the_post() ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile ?>
<?php endif ?>
With the above code I can show posts I add an expiration date , regardless of the date on which it expires , now want to know how I can delete them in a loop by comparing the date of expiration to the current date.
Try this, A Code Work is in my web site, first your
_expiration-date
key value format isY-m-d
means2015-10-17
must