WordPress.org

Make WordPress Core

Opened 15 months ago

Last modified 4 weeks ago

#47719 reviewing defect (bug)

Consistency issue with `include` parameter set to "0" in `WP_Term_Query`

Reported by: audrasjb Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Query Keywords: dev-feedback has-patch needs-unit-tests
Focuses: Cc:

Description (last modified by audrasjb)

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

$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

$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

$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.

Attachments (3)

47719.diff (510 bytes) - added by audrasjb 15 months ago.
Fix 47719 consistency issue with include parameter
47719.1.diff (646 bytes) - added by audrasjb 15 months ago.
Removing useless $inclusions var
47719.2.diff (642 bytes) - added by Hareesh Pillai 4 weeks ago.
Patch refreshed against trunk

Download all attachments as: .zip

Change History (8)

@audrasjb
15 months ago

Fix 47719 consistency issue with include parameter

#1 @audrasjb
15 months ago

  • Keywords has-patch needs-unit-tests added; needs-patch removed

47719.diff is fixing the issue on my side.

Credits: @loicblascos for the initial bug report on WP French Slack Team.

#2 @audrasjb
15 months ago

  • Description modified (diff)

@audrasjb
15 months ago

Removing useless $inclusions var

#3 @mukesh27
15 months ago

@audrasjb Patch 47719.1.diff working fine for me in the latest version

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 weeks ago

#5 @SergeyBiryukov
4 weeks ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

@Hareesh Pillai
4 weeks ago

Patch refreshed against trunk

Note: See TracTickets for help on using tickets.