I am trying to only show a single post per month on a query.
I can set the date as a variable and use something like the php array_unique function to check the dates and only echo out unique ones, however this feels a bit 'hacky'. Is there a built in query variable, or something built in WordPress I can use instead?
As for the 'hacky' option, I am quite new with PHP and struggling with using the aforementioned function. Checking the date is unique and only echoing out said variables when it is already inside a while loop is confusing me somewhat.
Below is the query I am using currently.
<?
$news_archive = array(
'post_type'=> 'news',
'posts_per_page' => 6,
'orderby' => 'date'
);
query_posts($news_archive);
echo '<ul class="related_links">';
while ( have_posts() ) : the_post();
$date = the_date('F m Y','','',false);
$date = explode(' ', $date);
$month_str = $date[0];
$month_int = $date[1];
$year = $date[2];
echo '<li><a href="/archive/news/' . $year . '/' . $month_int . '/">';
echo $month_str . ' ' . $year;
echo '</a></li>';
endwhile;
echo '</ul>';
endif;
wp_reset_query();
?>