[wp-trac] [WordPress Trac] #25680: is_main_query() _doing_it_wrong() notice suggests using WP_Query statically
WordPress Trac
noreply at wordpress.org
Thu Oct 24 09:42:46 UTC 2013
#25680: is_main_query() _doing_it_wrong() notice suggests using WP_Query statically
--------------------------+-----------------
Reporter: dd32 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 3.8
Component: Text Changes | Version:
Severity: normal | Keywords:
--------------------------+-----------------
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'));
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25680>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list