{"id":54674,"date":"2018-05-25T14:22:55","date_gmt":"2018-05-25T17:22:55","guid":{"rendered":"https:\/\/samuelchopard.ch\/wiki\/?p=54674"},"modified":"2019-03-18T14:29:18","modified_gmt":"2019-03-18T13:29:18","slug":"exclude-pages-from-wordpress-search-results","status":"publish","type":"post","link":"https:\/\/samuelchopard.ch\/wiki\/library\/exclude-pages-from-wordpress-search-results\/","title":{"rendered":"Exclude pages from WordPress search results"},"content":{"rendered":"<p><!--more--><\/p>\n<p>Paste the following in <strong><em>functions.php<\/em><\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\">\/\/Exclude pages from WordPress Search\r\nif (!is_admin()) {\r\nfunction wpb_search_filter($query) {\r\nif ($query-&gt;is_search) {\r\n$query-&gt;set('post_type', 'post');\r\n}\r\nreturn $query;\r\n}\r\nadd_filter('pre_get_posts','wpb_search_filter');\r\n}<\/pre>\n<p>Source:\u00a0<a target=\"_blank\" href=\"http:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-exclude-pages-from-wordpress-search-results\/\" rel=\"noopener\">http:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-exclude-pages-from-wordpress-search-results\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Paste the following in functions.php: \/\/Exclude pages from WordPress Search if (!is_admin()) { function wpb_search_filter($query) { if ($query-&gt;is_search) { $query-&gt;set('post_type', [...]","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[104,206,260],"class_list":["post-54674","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-exclude","tag-pages","tag-search"],"_links":{"self":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/comments?post=54674"}],"version-history":[{"count":1,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54674\/revisions"}],"predecessor-version":[{"id":54850,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54674\/revisions\/54850"}],"wp:attachment":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/media?parent=54674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/categories?post=54674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/tags?post=54674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}