[wp-trac] [WordPress Trac] #55955: Setting a 'NOT EXISTS' tax query in 'pre_get_posts' action triggers a fatal error in wp-includes/canonical.php
WordPress Trac
noreply at wordpress.org
Thu Jun 9 15:35:34 UTC 2022
#55955: Setting a 'NOT EXISTS' tax query in 'pre_get_posts' action triggers a fatal
error in wp-includes/canonical.php
--------------------------+-----------------------------
Reporter: codesdnc | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Canonical | Version: 6.0
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Under PHP8, the following code will fail on taxonomy archives: (is cut-
down to its minimal form)
{{{#!php
<?php
add_action( 'pre_get_posts', function( \WP_Query $query ){
$query->set( 'tax_query', array(
array(
'taxonomy' => 'post_format',
'operator' => 'NOT EXISTS',
),
) );
} );
}}}
Digging in the code, on line 334 of wp-includes/canonical.php, it assumes
that for each element in WP_Tax_Query->queried_terms, there will be a
'terms' entry that is an (a) defined, and (b) an array. However,
WP_Tax_Query::sanitize_query() (the only place I can see where
queried_terms is set) does NOT guarantee this for cases like above -- it
simply doesn't set a 'terms' entry for 'operator' => 'NOT EXISTS' queries
(which makes sense). This is only a nuisance before PHP8, which makes
passing non-arrays to count() throw an error.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55955>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list