Exclude specific pages from WP search results
-
Hi there,
I’ve been searching for a while now, trying to find the correct way to exclude certain pages from my WP search results. However, what I keep finding online are outdated ways of doing so, like this:
function ss_search_filter( $query ) { if ( !$query->is_admin && $query->is_search && $query->is_main_query() ) { $query->set( 'post__not_in', array( 1, 2, 3 ) ); } } add_action( 'pre_get_posts', 'ss_search_filter' );
Is there someone who could give me an updated version of this. Or at least tell me what has changed since then? For now, I’ll keep searching. If I DO come across some new code, I’ll post it here.
Thank you!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Exclude specific pages from WP search results’ is closed to new replies.