Problem: I want to list posts of a category, displaying those with custom-field 'start-date' after today (in the future) with order ASC. When this is done, I want to display all those with start-date before today (in the past) with order DESC.
The second list is no problem.
But the first list only displays the single most recent post when I use order => 'ASC'. If I use order => 'DESC',
all the posts display correctly.
Where do I fail in this code?
$args = array(
'cat' => $cat_id,
'meta_key' => 'dato-start',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'paged' => $paged
);
$arrangementer = new WP_Query($args);
if ( $arrangementer->have_posts() ) :
while ( $arrangementer->have_posts() ) : $arrangementer->the_post();
$today = date('Ymd');
$unnagjort = FALSE;
$startDato = get_post_meta(get_the_ID(), 'dato-start', TRUE);
$sluttDato = get_post_meta(get_the_ID(), 'dato-slutt', TRUE);;
if ( get_field('dato-start') && ($today > $startDato) ) $unnagjort = TRUE;
if (!$unnagjort) {
get_template_part( 'template-parts/content', get_post_format() );
}
endwhile;
Then I run rewind_posts()
and the same query, but order DESC, and filter out those with $unnagjort == TRUE.
The first query returns only the most recent requested post, the second returns all the requested posts.
dato-start
post meta values saved in? Are they a MySQL standard format? Do you have examples?