Support » Themes and Templates » Restrict Categories on Search Page?

  • Resolved bcreighton

    (@bcreighton)


    Hi,

    Is there anyway to exempt certain categories from being searched? I tried using query_posts() but it seemed to pulling all of those entries instead.

    Thanks,
    Beth

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    if( is_search() )  :
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("s=$s&paged=$paged&cat=-1,-11,-101");
    endif;
    ?>

    s=$s” is the key for this query; $s is a global variable in WordPress that holds the search phrase. Just change “cat=-1,-11,-101” to list the categories you need excluded (minus sign before each, naturally). That $paged part is explained here:

    http://wordpress.org/support/topic/57912#post-312858

    Perfect! Thank you! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Restrict Categories on Search Page?’ is closed to new replies.