[wp-trac] [WordPress Trac] #47719: Consistency issue with `include` parameter set to "0" in `WP_Term_Query`

WordPress Trac noreply at wordpress.org
Wed Jul 17 09:19:10 UTC 2019


#47719: Consistency issue with `include` parameter set to "0" in `WP_Term_Query`
-------------------------------------------------+-------------------------
 Reporter:  audrasjb                             |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Query                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  dev-feedback has-patch needs-unit-   |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------
Description changed by audrasjb:

Old description:

> There is a consistency issue with `include` parameter when used in
> `WP_Term_query`.
>
> If `include` is set to/contains `[0]`, the query doesn't return any
> result.
>
> This is not consistent with other query classes, like `WP_query` (using
> corresponding `post_in` parameter) and even more like `WP_User_query`
> (using the same `include` parameter).
>
> See reproductible examples below:
>
> **WP_Query**
> {{{#!php
> $args = array(
>         'post_type' => 'post',
>         'post__in' => [0],
> );
> $wp_query = new WP_Query( $args );
> if ( $wp_query->have_posts() ) :
>         while ( $wp_query->have_posts() ) :
>                 $wp_query->the_post();
>                 echo $post->ID;
>         endwhile;
> endif;
> }}}
> `=> returns no post`
>
> **WP_user_query**
> {{{#!php
> $args = array(
>         'role' => '',
>         'include' => [0],
> );
> $wp_user_query = new WP_User_Query( $args );
> $users = $wp_user_query->get_results();
> if ( ! empty( $users ) ) :
>         foreach ( $users as $user ) :
>                 echo $user->ID;
>         endforeach;
> endif;
> }}}
> `=> returns no user`
>
> **WP_Term_Query**
> {{{#!php
> $args = array(
>         'taxonomy' => 'category',
>         'include' => [0],
> );
> $wp_term_query = new WP_Term_query( $args );
> if ( ! empty( $wp_term_query->terms ) ) :
>         foreach ( $wp_term_query->terms as $term ) :
>                 echo $term->term_id;
>         endforeach;
> endif;
> }}}
> `=> returns all terms`
>
> Credits @loicblascos for the initial bug report.

New description:

 There is a consistency issue with `include` parameter when used in
 `WP_Term_query`.

 If `include` is set to/contains `[0]`, the query returns all terms.

 This is not consistent with other query classes, like `WP_query` (using
 corresponding `post_in` parameter) and even more like `WP_User_query`
 (using the same `include` parameter).

 Those doesn't return any result.

 See reproductible examples below:

 **WP_Query**
 {{{#!php
 $args = array(
         'post_type' => 'post',
         'post__in' => [0],
 );
 $wp_query = new WP_Query( $args );
 if ( $wp_query->have_posts() ) :
         while ( $wp_query->have_posts() ) :
                 $wp_query->the_post();
                 echo $post->ID;
         endwhile;
 endif;
 }}}
 `=> returns no post`

 **WP_user_query**
 {{{#!php
 $args = array(
         'role' => '',
         'include' => [0],
 );
 $wp_user_query = new WP_User_Query( $args );
 $users = $wp_user_query->get_results();
 if ( ! empty( $users ) ) :
         foreach ( $users as $user ) :
                 echo $user->ID;
         endforeach;
 endif;
 }}}
 `=> returns no user`

 **WP_Term_Query**
 {{{#!php
 $args = array(
         'taxonomy' => 'category',
         'include' => [0],
 );
 $wp_term_query = new WP_Term_query( $args );
 if ( ! empty( $wp_term_query->terms ) ) :
         foreach ( $wp_term_query->terms as $term ) :
                 echo $term->term_id;
         endforeach;
 endif;
 }}}
 `=> returns all terms`

 Credits @loicblascos for the initial bug report.

--

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


More information about the wp-trac mailing list