WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 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:
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)

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


4 years ago

#2 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #29660.

Note: See TracTickets for help on using tickets.