[wp-trac] [WordPress Trac] #42327: WP_Term_Query returns an empty array instead of 0

WordPress Trac noreply at wordpress.org
Wed Nov 1 15:45:06 UTC 2017


#42327: WP_Term_Query returns an empty array instead of 0
--------------------------------------+------------------------------
 Reporter:  xParham                   |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Taxonomy                  |     Version:  2.8.4
 Severity:  normal                    |  Resolution:
 Keywords:  has-unit-tests has-patch  |     Focuses:
--------------------------------------+------------------------------
Changes (by birgire):

 * keywords:   => has-unit-tests has-patch


Comment:

 I think the {{{terms}}} property should also be set as an empty array, so
 I slightly modified the patch from [attachment:42327.patch] to:

 {{{
 if ( 'count' == $args['fields'] ) {
         return 0;
 } else {
         $this->terms = array();
         return $this->terms;
 }

 }}}

 to avoid the mismatch between the {{{query()}}} method returning an empty
 array and the {{{terms}}} property being {{{null}}}, for the case when
 {{{fields}}} is not {{{count}}}. I think {{{terms}}} should be an empty
 array too in that case.

 [attachment:42327.2.diff] contains tests.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42327#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list