Filtering posts for unique titles, only the most recent

I am trying to understand how I can fetch posts for an archive that:

Have a unique title
Are the most recent version of said unique title

So, if I have 3 posts:

title: ‘ID1: My Title’
date: 01/01/18

title: ‘ID1: My Title’
date: 02/01/18

title: ‘ID1: My Title’
date: 03/01/18

I would only like to see the last, most recent one returned:

title: ‘ID1: My Title’
date: 03/01/18

This is my current query. I am using the Events Calendar plugin, hence the post_type:

$past_events = new WP_Query(array(
‘post_type’ => Tribe__Events__Main::POSTTYPE,
‘paged’ => $paged,
‘posts_per_page’ => ’10’,
‘eventDisplay’=>’past’,
‘orderby’=> ‘title’,
‘order’ => ‘ASC’,
‘s’ => $searchText ?: ”,
));

I’m wondering what to add to this query or if this is something I should try to accomplish with custom SQL? Any help would be much appreciated. Thanks!

Read more here:: Filtering posts for unique titles, only the most recent

Leave a Reply

Your email address will not be published. Required fields are marked *