Query params start_date and end_date not working when using ‘pre_get_post’ hook
-
Hi,
I want to alter the standard main query when accessing an events archive page. Therefore, I included some custom code in my plugin:
function my_alter_event_query($query){ if (!(is_admin()) && tribe_is_event_query() && $query->is_main_query()){ $query->set('eventDisplay', 'custom'); $query->set('start_date', '2016-10-01'); $query->set('end_date', '2017-02-27'); //var_dump($query); } } add_action('pre_get_posts', 'my_alter_event_query');
When dumping the $query object, I can see the added ‘start_date’ and ‘end_date’ query variables. However, the actual executed query in the custom template still renders the ‘default’ time range and does by no means regard the start_date and end_date values.
For custom templating, I simply use the original templates copied to my custom theme. There hasn’t been any other issue with that yet. And I’m using the original template functions, just altered some HTML markup in the list/loop.php template.
So, what am I missing here? Any help is much appreciated.
Best,Bunjip
- The topic ‘Query params start_date and end_date not working when using ‘pre_get_post’ hook’ is closed to new replies.