I have a WP-query that should show up to 20 posts of future events. The posts should be only from the post-format-aside and should be ordered by the date. That part works quite well. What does not work, that is to exclude events that have already passed. ( 'compare' => '>=', or 'meta_compare' => '>=', don't work. :( )Could anybody tell me, where is my mistake?
Thanks a lot! rabo
Here is my code:
<?php
$current_month = "";
setlocale(LC_ALL, 'de_DE@euro'); // Monatsnamen auf Deutsch ausgeben
$args = array( 'showposts' => 20,
'cat' => array
(1,2,7,8,9
),
'meta_key' => 'datumsfeld',
'orderby' => 'meta_value',
'compare' => '>=',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-aside',
)
)
);
$myQuery = new WP_Query( $args );
while ($myQuery->have_posts()) : $myQuery->the_post();
$datefield = DateTime::createFromFormat('Ymd', get_field('datumsfeld'));
if($datefield){
$month = $datefield->format("m");
$year = $datefield->format("Y");
if($month != $current_month){
echo '<div class="abstand"><strong>'.strftime("%B %Y",$datefield->getTimestamp()).'</div></strong>';
$current_month = $month;
}
}
?>