[wp-trac] [WordPress Trac] #33729: Non-Object Errors using `is_category()` For Categories That Don't Exist

WordPress Trac noreply at wordpress.org
Fri Sep 4 14:45:42 UTC 2015


#33729: Non-Object Errors using `is_category()` For Categories That Don't Exist
--------------------------------------+-----------------------------
 Reporter:  Howdy_McGee               |      Owner:
     Type:  defect (bug)              |     Status:  new
 Priority:  normal                    |  Milestone:  Awaiting Review
Component:  Taxonomy                  |    Version:  4.3
 Severity:  normal                    |   Keywords:
  Focuses:  administration, template  |
--------------------------------------+-----------------------------
 WordPress is throwing non-object errors whenever testing `is_category()`
 in `pre_get_posts` hook. This is easily replicable in the Twenty Fifteen
 Theme:

 {{{
 function theme_pgp( $query ) {
     if( is_admin() ) {
         return;
     }

     if( $query->is_main_query() && $query->is_category( 'uncategorized' )
 ) {
         $query->set( 'posts_per_page', 1 );
     }
 }
 add_action( 'pre_get_posts', 'theme_pgp' );
 }}}

 The error only shows up when passing parameters to `is_category()` and
 whenever viewing a category that does not exist
 `www.domain.com/blog/category/notexists/`

 Here is what the errors look like:

 {{{
 Notice: Trying to get property of non-object in /wp-includes/query.php on
 line 4154
 Notice: Trying to get property of non-object in /wp-includes/query.php on
 line 4156
 Notice: Trying to get property of non-object in /wp-includes/query.php on
 line 4158
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33729>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list