Skip to content
Browse files

Suppress query filters when called from get_posts(). fixes #7326 #745…

…7 for 2.6

git-svn-id: http://svn.automattic.com/wordpress/branches/2.6@8795 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent 3fb8795 commit d57a1e3d6bd7941233d90efd09e1c544a31a61e1 ryan committed Sep 1, 2008
Showing with 43 additions and 26 deletions.
  1. +1 −1 wp-includes/post.php
  2. +42 −25 wp-includes/query.php
View
2 wp-includes/post.php
@@ -465,7 +465,7 @@ function get_posts($args = null) {
'order' => 'DESC', 'include' => '',
'exclude' => '', 'meta_key' => '',
'meta_value' =>'', 'post_type' => 'post',
- 'post_parent' => 0
+ 'post_parent' => 0, 'suppress_filters' => true
);
$r = wp_parse_args( $args, $defaults );
View
67 wp-includes/query.php
@@ -775,7 +775,7 @@ function parse_query ($query) {
if ( !empty($qv['post_status']) )
$qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']);
- if ( $this->is_posts_page && !$qv['withcomments'] )
+ if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) )
$this->is_comment_feed = false;
$this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
@@ -829,7 +829,12 @@ function &get_posts() {
$join = '';
$search = '';
$groupby = '';
+ $fields = "$wpdb->posts.*";
$post_status_join = false;
+ $page = 1;
+
+ if ( !isset($q['suppress_filters']) )
+ $q['suppress_filters'] = false;
if ( !isset($q['post_type']) ) {
if ( $this->is_search )
@@ -1361,8 +1366,10 @@ function &get_posts() {
// Apply filters on where and join prior to paging so that any
// manipulations to them are reflected in the paging by day queries.
- $where = apply_filters('posts_where', $where);
- $join = apply_filters('posts_join', $join);
+ if ( !$q['suppress_filters'] ) {
+ $where = apply_filters('posts_where', $where);
+ $join = apply_filters('posts_join', $join);
+ }
// Paging
if ( empty($q['nopaging']) && !$this->is_singular ) {
@@ -1394,9 +1401,11 @@ function &get_posts() {
$cgroupby = '';
}
- $cjoin = apply_filters('comment_feed_join', $cjoin);
- $cwhere = apply_filters('comment_feed_where', $cwhere);
- $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
+ if ( !$q['suppress_filters'] ) {
+ $cjoin = apply_filters('comment_feed_join', $cjoin);
+ $cwhere = apply_filters('comment_feed_where', $cwhere);
+ $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
+ }
$this->comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss'));
$this->comment_count = count($this->comments);
@@ -1414,28 +1423,33 @@ function &get_posts() {
$where = "AND 0";
}
+ $orderby = $q['orderby'];
+
// Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
-
- $where = apply_filters('posts_where_paged', $where);
- $groupby = apply_filters('posts_groupby', $groupby);
- $join = apply_filters('posts_join_paged', $join);
- $orderby = apply_filters('posts_orderby', $q['orderby']);
- $distinct = apply_filters('posts_distinct', $distinct);
- $fields = apply_filters('posts_fields', "$wpdb->posts.*");
- $limits = apply_filters( 'post_limits', $limits );
+ if ( !$q['suppress_filters'] ) {
+ $where = apply_filters('posts_where_paged', $where);
+ $groupby = apply_filters('posts_groupby', $groupby);
+ $join = apply_filters('posts_join_paged', $join);
+ $orderby = apply_filters('posts_orderby', $orderby);
+ $distinct = apply_filters('posts_distinct', $distinct);
+ $fields = apply_filters('posts_fields', $fields);
+ $limits = apply_filters( 'post_limits', $limits );
+ }
// Announce current selection parameters. For use by caching plugins.
do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
// Filter again for the benefit of caching plugins. Regular plugins should use the hooks above.
- $where = apply_filters('posts_where_request', $where);
- $groupby = apply_filters('posts_groupby_request', $groupby);
- $join = apply_filters('posts_join_request', $join);
- $orderby = apply_filters('posts_orderby_request', $orderby);
- $distinct = apply_filters('posts_distinct_request', $distinct);
- $fields = apply_filters('posts_fields_request', $fields);
- $limits = apply_filters( 'post_limits_request', $limits );
+ if ( !$q['suppress_filters'] ) {
+ $where = apply_filters('posts_where_request', $where);
+ $groupby = apply_filters('posts_groupby_request', $groupby);
+ $join = apply_filters('posts_join_request', $join);
+ $orderby = apply_filters('posts_orderby_request', $orderby);
+ $distinct = apply_filters('posts_distinct_request', $distinct);
+ $fields = apply_filters('posts_fields_request', $fields);
+ $limits = apply_filters( 'post_limits_request', $limits );
+ }
if ( ! empty($groupby) )
$groupby = 'GROUP BY ' . $groupby;
@@ -1445,12 +1459,14 @@ function &get_posts() {
if ( !empty($limits) )
$found_rows = 'SQL_CALC_FOUND_ROWS';
- $request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
- $this->request = apply_filters('posts_request', $request);
+ $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
+ if ( !$q['suppress_filters'] )
+ $this->request = apply_filters('posts_request', $this->request);
$this->posts = $wpdb->get_results($this->request);
// Raw results filter. Prior to status checks.
- $this->posts = apply_filters('posts_results', $this->posts);
+ if ( !$q['suppress_filters'] )
+ $this->posts = apply_filters('posts_results', $this->posts);
if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
$cjoin = apply_filters('comment_feed_join', '');
@@ -1497,7 +1513,8 @@ function &get_posts() {
}
}
- $this->posts = apply_filters('the_posts', $this->posts);
+ if ( !$q['suppress_filters'] )
+ $this->posts = apply_filters('the_posts', $this->posts);
update_post_caches($this->posts);

0 comments on commit d57a1e3

Please sign in to comment.
Something went wrong with that request. Please try again.