Creating an monthly archive of custom posts based on ACF date picker




Hope someone more experienced than me can help me here. I’ve created a couple of custom post types called ‘ff_events’ and ‘ff_exhibitions’ in a site I’m developing. Via a date picker using the plugin Advanced Custom Fields, I’ve added ‘start’ and ‘end’ dates to these posts so I can use them to display the posts in chronological order.

Basically, I need to list monthly archives for both these custom post types based on their start dates i.e. I can’t use the plugin below as it shows custom post type archives based on the post’s publish date rather than using the start date custom field:

So, that’s where I’m at. I need to list monthly archives for my custom post types based on their custom field-set start dates and am lost as to how to do it!

Does anyone know how I can go about doing this?



PS, here’s a screenshot of what I’m trying to do (it’s very similar to what wp_get_archives() does in other words, but I need it to only show results for my two custom post types and the dates should refer to the custom field ‘start date’ rather than the post’s publish date).


wp_query and use the meta_key fields… the meta key is the custom field name


Thanks @Gareth_Gillman. Re-reading my post, I don’t think I explained it very well. I’m using wp_query along with the meta_key fields for the main loop and that’s working great. However, it’s the sidebar that I need to sort now - I need to do something like in the screenshot I posted above, very much like what you get from wp_get_archives($args);

The problem is that wp_get_archives(); returns archive links based on the post’s publish date, whereas I’m using the custom field ‘start_date’ to group together and organise my posts chronologically. It means that even using this plugin (which creates a new function called wp_get_archives_cpt($args); to specify which custom post types to return), I am only displaying post archive links based on the post’s publish date, not the custom field.

My current thinking is that I will need to first get all the post ID’s for the two custom post types I’m trying to display monthly archive links for (ff_events and ff_exhibitions), and then sort those ID’s into years and months based on their custom field ‘start_date’ before outputting them somehow, but I’m a bit stuck on how I would do that - any ideas?

Thanks again for getting back to me, it’s much appreciated!