WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Excluding Pages From Search Results

[Resolved] Excluding Pages From Search Results

Viewing 3 replies - 1 through 3 (of 3 total)
  • fatihturan
    Member

    @fatihturan

    For this i’m using Search Unleashed plugin.

    jamesstiff
    Member

    @jamesstiff

    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?

    niddler.wordpress
    Member

    @niddlerwordpress

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Excluding Pages From Search Results’ is closed to new replies.