On the main page has a block (which has its own design) with posts. These posts - announcements of events. Naturally, when they are already outdated, they continue to hang if you have not added new announcements ...
I would like to make an opportunity to ask the date until which the relevant announcements. So that when the announcement has already expired, it will not be displayed. And when there are no recent announcements, it did not appear to block announcements (his design).
On-the idea was to solve the problem of such a decision:
function filter_where($where = '') {
$expDate = date( 'Y-m-d', strtotime( get_post_meta($post->ID, 'aexp', true) ) );
$where .= " AND '" .$expDate >= date('Y-m-d', strtotime('-1 days')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'cat'=>28,
'posts_per_page' => 2
);
$my_query=new WP_Query($args);
remove_filter('posts_where', 'filter_where');
if( $my_query->have_posts() ) {
echo '<h2>Number of posts is '.count($my_query->posts) . '</h2>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><small><?php the_time('d.m.y') ?></small> <a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} else {echo "Нема постів!";}
//if ($my_query)
wp_reset_query();
But it did not work - posts are displayed, but outside of the dates and custom fields :(
Maybe someone knows how to implement a similar, but the working pattern?