Limit Search Results to Specific Post Types


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function SearchFilter($query) {
  2. if ($query->is_search) {
  3. $query->set('post_type',array('post','page'));
  4. }
  5. return $query;
  6. }
  7. add_filter('pre_get_posts','SearchFilter');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.