Suppress query filters when called from get_posts(). see #7326 #7547

git-svn-id: http://svn.automattic.com/wordpress/trunk@8766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-28 22:30:27 +00:00
parent c4919d8603
commit d927db8f2d
2 changed files with 37 additions and 24 deletions

View File

@ -453,7 +453,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 File

@ -837,6 +837,9 @@ class WP_Query {
if ( !isset($q['caller_get_posts']) )
$q['caller_get_posts'] = false;
if ( !isset($q['suppress_filters']) )
$q['suppress_filters'] = false;
if ( !isset($q['post_type']) ) {
if ( $this->is_search )
$q['post_type'] = 'any';
@ -1372,8 +1375,10 @@ class WP_Query {
// Apply filters on where and join prior to paging so that any
// manipulations to them are reflected in the paging by day queries.
if ( !$q['suppress_filters'] ) {
$where = apply_filters('posts_where', $where);
$join = apply_filters('posts_join', $join);
}
// Paging
if ( empty($q['nopaging']) && !$this->is_singular ) {
@ -1405,9 +1410,11 @@ class WP_Query {
$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);
@ -1427,7 +1434,7 @@ class WP_Query {
// Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
if ( !$q['suppress_filters'] ) {
$where = apply_filters('posts_where_paged', $where);
$groupby = apply_filters('posts_groupby', $groupby);
$join = apply_filters('posts_join_paged', $join);
@ -1435,11 +1442,13 @@ class WP_Query {
$distinct = apply_filters('posts_distinct', $distinct);
$fields = apply_filters('posts_fields', "$wpdb->posts.*");
$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.
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);
@ -1447,6 +1456,7 @@ class WP_Query {
$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;
@ -1457,10 +1467,12 @@ class WP_Query {
$found_rows = 'SQL_CALC_FOUND_ROWS';
$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', $request);
$this->posts = $wpdb->get_results($this->request);
// Raw results filter. Prior to status checks.
if ( !$q['suppress_filters'] )
$this->posts = apply_filters('posts_results', $this->posts);
if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
@ -1543,6 +1555,7 @@ class WP_Query {
}
}
if ( !$q['suppress_filters'] )
$this->posts = apply_filters('the_posts', $this->posts);
update_post_caches($this->posts);