Exclude pages in WordPress search result

If you want to exclude pages in search result i WordPress you just this to your functions.php.
If you just want to search for pages instead of posts you just change ’post’ to ’page’.

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

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>