function my_post_count_function( $year ) {
global $wpdb;
return $wpdb->get_var( "SELECT count(ID) FROM $wpdb->posts WHERE $wpdb->posts.post_type IN ('post') AND $wpdb->posts.post_status IN ('publish') AND YEAR($wpdb->posts.post_date) = $year" );
}
The function works, but I need help figuring out how to exclude the category. I believe I need to add a JOIN, but I’ve never joined tables in a query before. I’m unsure of how to begin and haven’t had much success in finding examples.
]]>function count_posts() {
$args = array(
'post_type' => 'post',
'year' => '2017',
'cat' => array(-667),
'posts_per_page'=>-1,
);
$the_query = new WP_Query( $args );
$count = $the_query->post_count;
wp_reset_query();
return $count;
}
Edit: added a missing prime before “posts_per_page”
]]>