Created
July 14, 2021 10:32
-
-
Save jorpdesigns/f6feb11464b578b31d114b29a69ec718 to your computer and use it in GitHub Desktop.
Snippet to exclude pages from WordPress search results
This file contains hidden or 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 | |
add_action('pre_get_posts','exclude_pages_from_search'); | |
function exclude_pages_from_search( $query ){ | |
if( $query->is_main_query() && is_search() ){ | |
$post_ids = array(123, 456, 345); // Replace with your own ids | |
$query->set('post__not_in', $post_ids); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment