Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#33729 closed defect (bug) (duplicate)

Non-Object Errors using `is_category()` For Categories That Don't Exist

Reported by: Howdy_McGee Owned by:
Priority: normal Milestone:
Component: Taxonomy Version: 4.3
Severity: normal Keywords:
Cc: Focuses: administration, template

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)

This ticket was mentioned in Slack in #core by howdy_mcgee. View the logs.


11 years ago

#2 @SergeyBiryukov
11 years ago

  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

Duplicate of #29660.

Note: See TracTickets for help on using tickets.