I am trying to add a filter on my custom theme based on post month, similar with the archives but with some differences.
What is the best way to get a list of months in witch we have posts?
I used the following query:
$wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"
Could not use the
wp_get_archives function because it returns only the following formats:
html - In HTML list (<li>) tags and before and after strings. This is the default. option - In select (<select>) or dropdown option (<option>) tags. link - Within link (<link>) tags. custom - Custom list using the before and after strings.