Created
April 24, 2024 11:14
-
-
Save gioacchinopoletto/38a6aa6553a39f700a64b5790a8af47f to your computer and use it in GitHub Desktop.
Wordpress, excude some pages from search
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
/* Exclude some pages from search */ | |
function gp_search_filter( $query ) { | |
if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) { | |
$query->set( 'post__not_in', array( 39,41 ) ); // add page ID's | |
} | |
} | |
add_action( 'pre_get_posts', 'gp_search_filter' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment