Custom archive query for certain category
-
Hey Guys,
I am trying to list archived posts by year but only for a certain category. I have a category called ‘blog’ and this has an id of ‘6’.
My current query is always returning 0..
Can anyone spot where I have gone wrong?
Query:
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON($wpdb->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) WHERE $wpdb->term_taxonomy.term_id = 6 AND $wpdb->term_taxonomy.parent = 6 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY post_date DESC");
sizeof($years) is always returned as 0 which means my query must be incorrect..
If anyone can help out, it would be appreciated ??
Cheers
- The topic ‘Custom archive query for certain category’ is closed to new replies.