I need help with a WordPress query to get posts.
I have an ACF-numeric-Field called "year".
I need a query to get posts who have entered a year, and the year is echoed as title.
Someting like
1925
- Post A
- Post B
- Post D
1926
- Post C
- Post E
This is waht I have so far to get posts with a "year" set and ordered by.
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'artikel',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'year',
'compare' => 'EXISTS'
),
array(
'key' => 'year',
'value' => 1900,
'type' => 'NUMERIC',
'compare' => '>'
)
)
);
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
Can someone help me how to put the year as the title?
2
Answers
You can try this one:
Hope it will be work!
If
$the_query
has values than you can do thisOf course change the html formating how ever you want