Search Widget
-
Is there a way to limit the search widget to only searching posts……and not pages. Almost every type of search that I try on my site usually includes my “Terms of Service” page in the search results. I only want the search results to display post content and not page content…is this possible?
Put this to your child theme’s
functions.phpfile (If you don’t know how to modify child theme functions, you may read this – How to modify the theme using a child theme)function searchfilter($query) {
if ($query->is_search) {
$query->set('post_type',array('post'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');Did that work?? If it’s working, please mark this thread as resolved..
Okay, what’s the URL of your site?
No…it did not work….here is a copy of my functions.php file. This is the first time I made a functions.php file to put in my child theme folder so i’m not sure if i did this correctly…..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
function searchfilter($query) {
if ($query->is_search) {
$query->set('post_type',array('post'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
</body>
</html>No! it’s not the HTML code. It’s php. So put codes between
<?phpand?>Put this in
functions.php<?php
function searchfilter($query) {
if ($query->is_search) {
$query->set('post_type',array('post'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
?>
Viewing 10 posts - 1 through 10 (of 12 total)
- 1
- 2
- You must be logged in to reply to this topic.
