Restrict Search Results to Pages or Posts in WordPress

In this tutorial I’ll show you how to quickly restrict your WordPress search results to either Pages or Posts through a simple snippet of code in the functions.php file.

Using Child Themes to allow for future updates without losing your modifications.

Code Snippet:

function SearchFilter($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’);
}
return $query;
}

add_filter(‘pre_get_posts’,’SearchFilter’);

Free tutorials for WordPress, Slider Revolution and Visual Composer. New tutorials added every Wednesday.

Take your WordPress website and skills to the next level!

SUBSCRIBE
https://www.youtube.com/channel/UCiTDv6q1XYwZnAm2EYN8wKw

LETS CONNECT:
https://twitter.com/WPTutz

SUPPORT: Our website offers additional information and perks. Please check it out! https://wptuts.co.uk