[wp-trac] [WordPress Trac] #46350: If a term is '0' clicking on its "Count" value displays all posts
WordPress Trac
noreply at wordpress.org
Wed Mar 6 17:14:40 UTC 2019
#46350: If a term is '0' clicking on its "Count" value displays all posts
--------------------------+-----------------------------
Reporter: jesin | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Taxonomy | Version: 3.1
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+-----------------------------
Comment (by jesin):
I tracked down this issue to this
[https://core.trac.wordpress.org/browser/tags/5.1/src/wp-includes/class-
wp-tax-query.php#L604 array_filter] function. Before being passed through
this function the `$query` variable contains the following data:
{{{
Array
(
[taxonomy] => category
[terms] => Array
(
[0] => 0
)
[field] => name
[operator] => IN
[include_children] => 1
)
}}}
The array in the `terms` index is removed by `array_filter()`.
How about replacing it with
{{{
$terms = array_filter( $query['terms'], function( $term ) { return ( 0 !==
strlen( trim( $term ) ) ); } );
}}}
Also this issue occurs even when programmically retrieving posts using
`tax_query`. The following code returns an empty array even if there are
posts assigned to the "0" category.
{{{
get_posts( array( 'posts_per_page' => -1, 'fields' => 'ids', 'tax_query'
=> array( array( 'taxonomy' => 'category', 'field' => 'name', 'terms' =>
'0' ) ) ) )
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46350#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list