• Aloha πŸ™‚

    I got a little problem… I want to create a searchform that exclude all post and some specific pages. My website is [url=http://www.ukuleleroot.com]

    I have searched and found a couple of solutions, but no one that have worked for me.

    I have succeeded creating a searchform there will exclude all post (where -1,-5,-6 are the id’s of the post category’s):

    <form method=”get” id=”searchform” action=”<?php bloginfo(‘url’); ?>/”>
    <div>
    <input type=”text” value=”<?php the_search_query(); ?>” name=”s” id=”s” />

    <input type=”hidden” name=”cat” value=”-1,-5,-6,” />

    <input type=”submit” id=”searchsubmit” value=”<?php _e(‘Search’,’Glow’); ?>” />
    </div>
    </form>

    Is it possible to add a ekstra input there will sort out page id’s?

    If that isn’t possible; I have found a code to be placed in functions.php:

    function SearchFilter($query) {
    if ($query->is_search) {
    $query->set(‘post_type’,’post’);
    $query->set(‘cat’,’-1,-5,-6,’);
    }
    return $query;
    }
    add_filter(‘pre_get_posts’,’SearchFilter’);

    But the code just remove all pages :O

    Best regards BjΓΈrn Jensen

The topic ‘exclude specific pages from search’ is closed to new replies.