is_main_query() _doing_it_wrong() notice suggests using WP_Query statically
|Reported by:||dd32||Owned by:||wonderboymusic|
|Component:||Text Changes||Keywords:||has-patch commit|
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 (14)
- Keywords 2nd-opinion close added
- Milestone changed from 3.8 to Awaiting Review
- Keywords 2nd-opinion close removed
- Milestone changed from Awaiting Review to 4.4
- Owner set to DrewAPicture
- Status changed from new to assigned
9 months ago
- Keywords has-patch commit added
- Owner changed from DrewAPicture to wonderboymusic