WordPress.org

Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#48029 new defect (bug)

WP_Query::query only using a single post_status

Reported by: useStrict Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

While investigating why bbp_forum_get_subforums() was not returning private forums while being a keymaster, I found that WP_Query::query() will only use the first post_status of a given array.

E.g:

 WP_Query Object
        (
            [query] => Array
                (
                    [post_parent] => 5420
                    [post_type] => forum
                    [post_status] => Array
                        (
                            [0] => publish
                            [1] => private
                            [2] => hidden
                        )

                    [posts_per_page] => 50
                    [orderby] => menu_order title
                    [order] => ASC
                    [ignore_sticky_posts] => 1
                    [no_found_rows] => 1
                )
...
            [request] => SELECT   wpp_posts.ID FROM wpp_posts  WHERE 1=1  AND wpp_posts.post_parent = 5420  AND wpp_posts.post_type = 'forum' AND ((wpp_posts.post_status = 'publish'))  ORDER BY wpp_posts.menu_order ASC, wpp_posts.post_title ASC LIMIT 0, 50

The same thing applies if you pass it a comma-separated string of statuses:

WP_Query Object
        (
            [query] => Array
                (
                    [post_parent] => 5420
                    [post_type] => forum
                    [post_status] => publish,private,hidden
                    [posts_per_page] => 50
                    [orderby] => menu_order title
                    [order] => ASC
                    [ignore_sticky_posts] => 1
                    [no_found_rows] => 1
                )
...
            [request] => SELECT   wpp_posts.ID FROM wpp_posts  WHERE 1=1  AND wpp_posts.post_parent = 5420  AND wpp_posts.post_type = 'forum' AND ((wpp_posts.post_status = 'publish'))  ORDER BY wpp_posts.menu_order ASC, wpp_posts.post_title ASC LIMIT 0, 50

Steps to replicate (taken from bbpress/includes/forums/template.php):

$r = bbp_parse_args( $args, array(
                'post_parent'         => 0,
                'post_type'           => bbp_get_forum_post_type(),
                 'post_status'         => implode( ',', $post_stati ),
                // 'post_status'         => $post_stati,
                'posts_per_page'      => get_option( '_bbp_forums_per_page', 50 ),
                'orderby'             => 'menu_order title',
                'order'               => 'ASC',
                'ignore_sticky_posts' => true,
                'no_found_rows'       => true
        ), 'forum_get_subforums' );
        $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );

        // Create a new query for the subforums
        $get_posts = new WP_Query();

        // No forum passed
        $sub_forums = !empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array();

Change History (1)

#1 @useStrict
5 weeks ago

  • Summary changed from WP_query::query only using a single post_status to WP_Query::query only using a single post_status
Note: See TracTickets for help on using tickets.