WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#37962 closed defect (bug) (fixed)

NOT EXISTS tax_query triggers debug notice on get_queried_object()

Reported by: johnjamesjacoby Owned by: boonebgorges
Milestone: 4.7 Priority: normal
Severity: normal Version: 3.8
Component: Taxonomy Keywords: has-patch has-screenshots
Focuses: Cc:

Description

When querying for post objects without taxonomy terms, a debug notice is triggered. (This doesn't happen with the built-in taxonomies, because they have old weird special-casing.)

Notice: Undefined index: terms in /srv/www/wordpress-develop/src/wp-includes/class-wp-query.php on line 3267

Example code:

add_action( 'admin_init', function() {
	$posts = new WP_Query( array(
		'post_type' => 'event',
		'tax_query' => array( array(
			'taxonomy'         => 'event-category',
			'operator'         => 'NOT EXISTS',
			'include_children' => false
		) )
	) );

	var_dump( $posts->get_queried_object() ); die;
} );

Patch imminent.

Attachments (2)

Screen Shot 2016-09-06 at 16.08.43.png (208.2 KB) - added by johnjamesjacoby 7 months ago.
Screenshot of xdebug output
37962.patch (531 bytes) - added by johnjamesjacoby 7 months ago.
Wrap $query['terms'] in an empty() check

Download all attachments as: .zip

Change History (6)

@johnjamesjacoby
7 months ago

Screenshot of xdebug output

@johnjamesjacoby
7 months ago

Wrap $query['terms'] in an empty() check

#1 @johnjamesjacoby
7 months ago

Last touch was r26874, which is possibly what revealed this notice, but not when the logical error was introduced.

NOT EXISTS queries will never return terms, so it makes sense that it would not be set at this time.

Last edited 7 months ago by johnjamesjacoby (previous) (diff)

#2 @boonebgorges
7 months ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to boonebgorges
  • Status changed from new to assigned

Thanks for the patch. Looks good to me.

This raises a semi-related issue, which is that the change in [30711] renders the wp_list_filter() just above this block superfluous; there's no point in filtering terms (rather than clauses) by operator, and in any case, queried_terms always necessarily contains the matched terms rather than not-matched terms. I'll pull that out under the guise of the current ticket as well.

#3 @boonebgorges
7 months ago

In 38585:

Query: Avoid PHP notice in get_queried_object() when query contains NOT EXISTS tax query.

Props johnjamesjacoby.
See #37962.

#4 @boonebgorges
7 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 38586:

Query: Eliminate unnecessary wp_list_filter() call in get_queried_object().

The refactor in [30711] swapped out the old queries property for the
new queried_terms, but should also have gotten rid of the now-
superfluous wp_list_filter() call.

Fixes #37962.

Note: See TracTickets for help on using tickets.