Opened 10 years ago
Closed 10 years ago
#33729 closed defect (bug) (duplicate)
Non-Object Errors using `is_category()` For Categories That Don't Exist
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.3 |
| Component: | Taxonomy | Keywords: | |
| Focuses: | administration, template | Cc: |
Description
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
Change History (2)
Note: See
TracTickets for help on using
tickets.
Duplicate of #29660.