is_main_query() _doing_it_wrong() notice suggests using WP_Query statically
|Reported by:||dd32||Owned by:|
|Component:||Text Changes||Keywords:||2nd-opinion close|
At present when is_main_query() is called within the pre_get_posts hook, it returns a _doing_it_wrong() error which refers to replacing it with WP_Query::is_main_query(). Obviously it's saying call the method on the WP_Query object, but some people can take that literally and call it statically.
Notice: is_main_query was called incorrectly. In pre_get_posts, use the WP_Query::is_main_query() method, not the is_main_query() function.
We should instead, make mention to checking the passed $query object via $query->is_main_query() instead somehow.
Example of how it was incorrectly used:
if (( is_front_page() || is_home()) && WP_Query::is_main_query()) $query->set('post_type', array('wp_meetup_event', 'post'));
Change History (10)
- Keywords 2nd-opinion close added
- Milestone changed from 3.8 to Awaiting Review