Ticket #3234: 3234.2.patch
File 3234.2.patch, 1.5 KB (added by , 6 years ago) |
---|
-
src/includes/forums/functions.php
2052 2052 $posts_query->set( 'post__not_in', $not_in ); 2053 2053 2054 2054 // Some other post type besides Forums, Topics, or Replies 2055 } elseif ( !array_diff( $post_types, bbp_get_post_types() ) ) {2055 } elseif ( array_diff( $post_types, bbp_get_post_types() ) ) { 2056 2056 2057 2057 // Get forums to exclude 2058 2058 $forum_ids = bbp_exclude_forum_ids( 'meta_query' ); … … 2063 2063 } 2064 2064 2065 2065 // Get any existing meta queries 2066 $meta_query 2066 $meta_query = (array) $posts_query->get( 'meta_query', array() ); 2067 2067 2068 // Add our meta query to existing 2069 $meta_query[] = $forum_ids; 2068 // Don't add another meta query if there is already a complex meta 2069 // relationship being queried for, or an "AND" query we shouldn't touch. 2070 if ( isset( $meta_query['relation'] ) && ( $meta_query['relation'] != 'OR' ) ) { 2071 return; 2072 } 2070 2073 2074 // This condition avoids interferece with non-bbPress queries, making 2075 // the presence of _bbp_forum_id meta key on posts be optional. 2076 $not_bbp = array( 2077 'key' => '_bbp_forum_id', 2078 'compare' => 'NOT EXISTS', 2079 'value' => '' 2080 ); 2081 2082 // Add forum IDs and NOT EXISTS to a separate meta-query condition 2083 $meta_query[] = array( 2084 'relation' => 'OR', 2085 $forum_ids, 2086 $not_bbp 2087 ); 2088 2071 2089 // Set the meta_query var 2072 2090 $posts_query->set( 'meta_query', $meta_query ); 2073 2091 }