Blog for web designers

Search only post type wordpress

By default wordpress search provides an searching function on whole site whether it is pages or post type. In order to make the search only post type in wordpress, below is the code you need to copy and paste it in to your function.php file.

Search only post type

function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');

Santosh Shah

My name is Santosh Shah and blogs at santosh-shah.com


Reader Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.