WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding Pages From Search Results (4 posts)

  1. fatihturan
    Member
    Posted 5 years ago #

    How i can exclude pages from search results?

  2. fatihturan
    Member
    Posted 5 years ago #

    For this i'm using Search Unleashed plugin.

  3. jamesstiff
    Member
    Posted 5 years ago #

    There's a great tutorial here.

    In short, just add this to your theme's functions.php file (or create the file if it doesn't exist):

    <?php
    function mySearchFilter($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    }
    return $query;
    }
    
    add_filter('pre_get_posts','mySearchFilter');
    ?>

    I'd be very interested to know how to combine the page exclude function above with the ability to exclude posts by tag. I'm guessing there's a simple solution?

  4. niddler.wordpress
    Member
    Posted 4 years ago #

    Cheers James - that's brilliant - taken me ages to find it, such a simple solution!

Topic Closed

This topic has been closed to new replies.

About this Topic