Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1120529

    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…

    #1120558

    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

    #1120711

    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’ );

    • This reply was modified 5 years, 7 months ago by abavarianboy.
    #1120715

    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

    #1120722
    This reply has been marked as private.
    #1120724

    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

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Exclude a single Page or Post from Search (ajax results)’ is closed to new replies.