I've got an "event" custom post type, with a meta field is used for the event date. I've successfully created archive pages (year and month) based on the answer on a previous question (here). Now, I'm trying to create a listing of the archives, sort of like wp_get_archives would work. Example:
2012
- January
- February
- March
- etc
2011
- January
- February
- March
- etc
The query I'm running to gather up all the dates from the meta_key is this:
$query = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'event_date' ORDER BY meta_value DESC" );
But I'm not sure how I can take that data and list it out like the above example. I know I can output the unique dates as is with a foreach loop. That, my output is as follows:
2012-07-15 2011-06-07 2011-01-10
Trying to get it all sorted in the list format, I'm completely unsure of. Any help with this one is greatly appreciated!
wp_get_archives()
uses isSELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit
, have you tried something along those lines?SELECT YEAR(meta_value) as 'year', MONTH(meta_value) AS 'month'
...etc, and apply your ownWHERE
seems to me like a solid way of approaching it. If you have not tried this method, I'll write it up as a solution for you.