search ]

Limit WordPress Search to a Specific Post Type

The following snippet lets you limit WordPress search to a specific Custom Post Type so results come only from that post type. Add to functions.php and set the post type(s) to search on line 4:

function SearchFilter($query) {
  if ($query->is_search) {
    // Insert the specific post type you want to search
    $query->set('post_type', 'feeds');
  }
  return $query;
}

add_filter('pre_get_posts','SearchFilter');
Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo