Filtering my custom post type by published year. I have something like this:
Filter posts for 2015 / 2016.
The years are links which redirecting with $_GET vars like '?year=2015' and '?year=2016'
In the custom page i have this:
$year = isset($_GET['year']) ? $_GET['year'] : '';
if ($year == '2015') {
$the_query = new WP_Query('year=2015&post_type=events');
} else {
$the_query = new WP_Query('post_type=events');
}
But if i click the 2015 year i'm redirecting to 404 page. I tried make query like this $the_query = new WP_Query('year=2015&post_type=events'); and it works, but cannot make it work with the GET or is there a better way to do that? (sorry for my English)
Also tried this:
$year = isset($_GET['year']) ? $_GET['year'] : '';
$the_query = new WP_Query('year='. (int)$year .'&post_type=events');
And here is problem that my 2016 posts are filtering but if i pass 2015 to GET parametr im redirecting to 404 page.