Pawan Kumawat

Search only posts (not pages) in WordPress

How To Limit Search Results For Specific Post Types in WordPress


Have you ever tried  to  limit your search results to specific post types? Its not very hard.

We can modify the search feature in WordPress by modifying the functions.php file.


This is very easy with using this default hook.




function searchfilter($query) {
    if ($query->is_search && !is_admin() ) {
return $query;


See the line that says




By modifying this you can easily modify particular post type for search. simply add or remove particular post type in array variables.


Share This On :

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Request A Quote