Created
December 8, 2014 06:32
-
-
Save joshuadavidnelson/681d08913a36eda69121 to your computer and use it in GitHub Desktop.
SQL to get years of posts in specific category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Custom query. Change the number in parenthesis on line 10 to your category id | |
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts | |
FROM $wpdb->posts wp_posts INNER JOIN $wpdb->term_relationships | |
ON (wp_posts.ID = $wpdb->term_relationships.object_id) | |
INNER JOIN $wpdb->term_taxonomy | |
ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) | |
AND $wpdb->term_taxonomy.taxonomy = 'category' | |
AND $wpdb->term_taxonomy.term_id IN (1) | |
$where GROUP BY YEAR(post_date) | |
ORDER BY post_date $order"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment