WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#47719 new defect (bug)

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

Reported by: audrasjb Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: dev-feedback has-patch needs-unit-tests
Focuses: Cc:
PR Number:

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 (2)

47719.diff (510 bytes) - added by audrasjb 3 months ago.
Fix 47719 consistency issue with include parameter
47719.1.diff (646 bytes) - added by audrasjb 3 months ago.
Removing useless $inclusions var

Download all attachments as: .zip

Change History (5)

@audrasjb
3 months ago

Fix 47719 consistency issue with include parameter

#1 @audrasjb
3 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
3 months ago

  • Description modified (diff)

@audrasjb
3 months ago

Removing useless $inclusions var

#3 @mukesh27
3 months ago

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

Note: See TracTickets for help on using tickets.