Title: add_filter posts_results
Last modified: September 25, 2018

---

# add_filter posts_results

 *  Resolved [c3iqwp](https://wordpress.org/support/users/c3iqwp/)
 * (@c3iqwp)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/add_filter-posts_results/)
 * I want to filter the results of a search. I need to examine the result set and
   remove some posts based on the existence of others. I beleive that the filter
   posts_results is the correct filter to use but when I dump the $posts array I
   only get one object. That happens to be the only embedded video on the site and
   not a post.
 * I changed the filter to return an empty array but it doesn’t change the results
   on the search page. This is from the codex example. I stopped at the point where
   the ‘error_log(print_r($posts, true));’ returns just one result where the search
   page displays several results.
 *     ```
       function preferCustomContentFilter($posts) {
         $filtered_posts = array();
         error_log(print_r($posts, true));
         foreach ($posts as $post) {
       error_log("HERE");
           if (false === strpos($post->post_title, 'selfie')) {
           // safe to add non-selfie title post to array
           $filtered_posts[] = $post;
           }
         }
         //return $filtered_posts ;
   
         // try to affect the search/results page
         return array();
       }
       add_filter('posts_results', 'preferCustomContentFilter');
       ```
   
    -  This topic was modified 7 years, 7 months ago by [c3iqwp](https://wordpress.org/support/users/c3iqwp/).
      Reason: Added code marks
    -  This topic was modified 7 years, 7 months ago by [c3iqwp](https://wordpress.org/support/users/c3iqwp/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [c3iqwp](https://wordpress.org/support/users/c3iqwp/)
 * (@c3iqwp)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/add_filter-posts_results/#post-10721070)
 * I needed to look at ‘the_posts’ rather than ‘post_results’ and the add_filter
   needed a lower priority:
 * `add_filter('the_posts', 'preferCustomContentFilter', 1000);`

Viewing 1 replies (of 1 total)

The topic ‘add_filter posts_results’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [c3iqwp](https://wordpress.org/support/users/c3iqwp/)
 * Last activity: [7 years, 7 months ago](https://wordpress.org/support/topic/add_filter-posts_results/#post-10721070)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
