[wp-trac] [WordPress Trac] #48029: WP_query::query only using a single post_status

WordPress Trac noreply at wordpress.org
Thu Sep 12 18:27:51 UTC 2019


#48029: WP_query::query only using a single post_status
--------------------------+-----------------------------
 Reporter:  useStrict     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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();
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48029>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list