Posted By

myke on 08/18/10


Tagged

search wordpress only wp result posts


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

srdjan


Only search WP posts


 / Published in: PHP
 

To exclude pages from wordpress search results include the following in your theme's functions.php

  1. /*
  2.  *Only Search Posts
  3.  */
  4. function SearchFilter($query) {
  5. if ($query->is_search) {
  6. $query->set('post_type', 'post');
  7. }
  8. return $query;
  9. }
  10.  
  11. add_filter('pre_get_posts','SearchFilter');

Report this snippet  

You need to login to post a comment.