I would use WP_Query
for this, as I am more comfortable with it.
There are two solutions to this that occur to me. If you’re not heartset on the categories, then WP_Query
has good support for date parameters, to include a year
parameter. A query by year would look something like this:
$wpse176213_query = new WP_Query( array(
'nopaging' => true, // return all posts
'year' => $your_year_var // Must by 4 digit
) );
If you’re heartset on using your categories, WP_Query
also supports that. That would look something like this:
$wpse166213_query = new WP_Query( array(
'nopaging' => true, // return all posts
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'slug',
// Whatever the slug for the year category is
'terms' => $your_year_slug
)
) );
Note that, if you like, you can do a simpler query without using tax_query
, but I tend to favor tax_query
as it allows you to extend the code with less additional effort, if you ever run into that. Also note that these queries are not complete, I strongly recommend you read through the (long) list of available parameters and make sure you set them up correctly. See the codex entry for WP_Query
.