[wp-trac] [WordPress Trac] #27015: WP_Query::get_queried_object() does not always work in 'pre_get_posts'

WordPress Trac noreply at wordpress.org
Sat Jul 10 07:37:03 UTC 2021


#27015: WP_Query::get_queried_object() does not always work in 'pre_get_posts'
-------------------------------------------------+-------------------------
 Reporter:  bcworkz                              |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Query                                |     Version:  3.8
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-unit-tests needs-    |     Focuses:
  refresh                                        |
-------------------------------------------------+-------------------------

Comment (by oglekler):

 I stumbled on the same notice. The notice appeared when wp-blog-header.php
 calls wp() function.

 I've used filter 'pre_get_posts' for products in condition:
 {{{
 ( is_shop() || is_front_page() )
 }}}

 and both functions call 'is_page()' which results in $page_obj is not an
 object.

 I solved this for myself by reordered conditions in the if statement
 checking
 {{{
 isset( $query->query['post_type'] )
 }}}
 first.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/27015#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list