Opened 6 years ago
Last modified 5 years ago
#48029 new defect (bug)
WP_Query::query only using a single post_status
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | |
Focuses: | Cc: |
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 (2)
Note: See
TracTickets for help on using
tickets.