Skip to content

Instantly share code, notes, and snippets.

@AntoscencoVladimir
Last active February 14, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntoscencoVladimir/c89e63b67d8051df272e to your computer and use it in GitHub Desktop.
Save AntoscencoVladimir/c89e63b67d8051df272e to your computer and use it in GitHub Desktop.
Disable pages from search Wordpress
О том, как из результатов поиска на 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