Hi,
I’m struggling to exclude a single page from the ajax search results – can you please provide a hint how to do so? I had a look on an older post from 2016 leading to install Relevanssi but it seems to be outdated as the core of the plugin is included in the newer theme version.
Even when I additionally installed Relevanssi and choose the specific page id not to show in the search results, it still appears…
Hey abavarianboy,
Perhaps this article will help, please scroll down to “Excluding Categories From The Search”
But this plugin might be easier: Search Exclude
Best regards,
Mike
Yes that works for the search result page but not for the ajax hints in the top menu search. The page is still suggested…
But the plugin works.
// Exclude specific posts/pages from search
// https://www.wpexplorer.com/limit-wordpress-search/
function exclude_pages_from_search($query) {
if ( $query->is_main_query() && is_search() ) {
$exclude_ids = array( 266, 156 ); // Array of the ID’s to exclude
$query->set( ‘post__not_in’, $exclude_ids );
}
return $query;
}
add_filter( ‘pre_get_posts’,’exclude_pages_from_search’ );
Hi,
Glad to hear that the plugin works, unless there is anything else we can help with on this issue, shall we close this then?
Best regards,
Mike
Hi,
Glad we were able to help, we will close this now. Thank you for using Enfold.
For your information, you can take a look at Enfold documentation here
For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)
Best regards,
Mike