Last active
July 27, 2019 11:19
-
-
Save thierrypigot/727460d160ef43a027d9 to your computer and use it in GitHub Desktop.
Exclude page / category from search on WordPress frontend
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
<?php | |
/** | |
* Exlcude categories ids: 2, 3 and 5 | |
**/ | |
function tp_SearchFilter($query) | |
{ | |
if( !$query->is_admin && $query->is_search ) | |
{ | |
$query->set( 'category__not_in', array( 2, 3, 5 ) ); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','tp_SearchFilter'); |
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
<?php | |
/** | |
* Exlcude page ids: 12, 23 and 65 | |
**/ | |
function tp_SearchFilter($query) | |
{ | |
if( !$query->is_admin && $query->is_search ) | |
{ | |
$query->set( 'post__not_in', array( 12, 23, 65 ) ); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','tp_SearchFilter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment