Last active
February 14, 2016 09:55
-
-
Save AntoscencoVladimir/c89e63b67d8051df272e to your computer and use it in GitHub Desktop.
Disable pages from search Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
О том, как из результатов поиска на WordPress можно исключить ВСЕ страницы. | |
Под ‘страницами’ здесь я подразумеваю одноименный тип контента. | |
<?php | |
function bez_stranic_v_poiske($zapros) { | |
if ($zapros->is_search) : | |
$zapros->set('post_type', 'post'); | |
endif; | |
return $zapros; | |
} | |
add_filter('pre_get_posts', 'bez_stranic_v_poiske'); | |
?> | |
Обратите внимание на четвертую по счету строчку, — там я задаю включение в поиск посты типа «запись», только посты типа «запись», что автоматически исключает участие в поиске страниц. | |
И наоборот исключить записи, но включить pages можно вот так: | |
<?php | |
function bez_stranic_v_poiske($zapros) { | |
if ($zapros->is_search) : | |
$zapros->set('post_type', 'page'); | |
endif; | |
return $zapros; | |
} | |
add_filter('pre_get_posts', 'bez_stranic_v_poiske'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment