I have content type event
that has date
field
and i created view "events" to this content type and added contextual filter "Date".
The problem is in the database the field date value is stored with this format
2007-01-17T00:00:00
and I want to filter like this events/2007
. Unfortunately, I get no results because the URL should be like this events/2007-01-17T00:00:00
.
So what is the solution for making it work with this events/2007
by altering
the query using views_views_query_alter()
instead of creating field that hold the value like this 2007
. I believe that altering the query by this way should solve it but it didn't
function views_views_query_alter(&$view, &$query) {
if ($view->name == 'events' && is_numeric(arg(1)) ) {
$view->query->where[0]['conditions'][3]['field']=" YEAR('field_data_field_date.field_date_value')";
}
}