WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Restrict Categories on Search Page? (3 posts)

  1. bcreighton
    Member
    Posted 6 years ago #

    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

  2. Kafkaesqui

    Posted 6 years ago #

    <?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

  3. bcreighton
    Member
    Posted 6 years ago #

    Perfect! Thank you! :)

Topic Closed

This topic has been closed to new replies.

About this Topic