apply_filters_ref_array( 'posts_results', WP_Post[] $posts, WP_Query $query )

Filters the raw post results array, prior to status checks.


Parameters Parameters

$posts

(WP_Post[]) Array of post objects.

$query

(WP_Query) The WP_Query instance (passed by reference).


Top ↑

More Information More Information

The input of this filter is an array of posts, created by any(?) WP_Query looking for posts.


Top ↑

Source Source

File: wp-includes/class-wp-query.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    Example migrated from Codex:

    Code sample for filtering an array of posts results and return an array of post objects which does not have the word “selfie” in the title.

    add_filter( 'posts_results', 'my_posts_results_filter' );
    
    function my_posts_results_filter( $posts ) {
    	$filtered_posts = array();
    	print_r( $posts );
    	foreach ( $posts as $post ) {
    		if ( false === strpos($post->post_title, 'selfie')) {
    			// safe to add non-selfie title post to array
    			$filtered_posts[] = $post;
    		}
    	}
    	return $filtered_posts ;
    }
    

You must log in before being able to contribute a note or feedback.