All Posts by Email, Once a Week

Media Temple logo

CSS-Tricks is brought to you in part by Media Temple, the web hosting that we both use and recommend.

Multiple Custom Search pages

  • # October 3, 2012 at 3:31 pm

    How would I go about having 5 search pages on my site, each of which searches within a different category?

    I know I would use this in my functions.php if I wanted the search functionality on the whole site to only search specific categories.

    function SearchFilter($query) {
    if ($query->is_search) {
    // Insert the specific categories you want to search
    $query->set(‘cat’, ‘8,9,12’);
    }
    return $query;
    }

    add_filter(‘pre_get_posts’,’SearchFilter’);

    Or is the answer to only return or echo the results from certain categories?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed