• tontamoo

    (@tontamoo)


    Is there a way to exclude the content of a certain category (e.g. protected entries) from being searched or appearing in the search results?
    Right now, it’ll display the protected entries along with the search results. It’ll still ask you to login to view the actual entry, but still, it defeats the purpose of the protected entry since readers will know a little bit about the content of the protected entry.

Viewing 5 replies - 1 through 5 (of 5 total)
  • hey, i know exactly how to do what you guys want.

    to limit search results to a specific category you have to include an if/then test inside TheLoop. hopefully everyone will take example from me and learn it’s better to INCLUDE CONTEXTUAL EXAMPLES! here’s mine :

    ** original code from search.php, using wp1.5.1 **
    <?php while (have_posts()) : the_post(); ?>

    <div class=”post”>
    <h3 id=”post-<?php the_ID(); ?>”>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h3>
    <small><?php the_time(‘l, F jS, Y’) ?></small>

    <div class=”entry”>
    <?php the_excerpt() ?>
    </div>

    <p class=”postmetadata”>Posted in <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’,”,’|‘); ?> <?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?></div>

    <?php endwhile; ?>

    ** modified code to search cat2, using wp1.5.1 **
    <?php while (have_posts()) : the_post(); ?>

    <?php if ( in_category(2) ) { ?> <!– check to see if this is in cat2 –>

    <div class=”post”>
    <h3 id=”post-<?php the_ID(); ?>”>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h3>
    <small><?php the_time(‘l, F jS, Y’) ?></small>

    <div class=”entry”>
    <?php the_excerpt() ?>
    </div>

    <p class=”postmetadata”>Posted in <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’,”,’|‘); ?> <?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?></div>

    <?php } ?> <!– Close the if statement. –>

    <?php endwhile; ?>

    **end of code**

    as you can see, you simply use the if/then (which i commented) to check and make sure the post being run thru the loop is inside your specified category. copy and paste the code to a text editor to look at it without word-wrap, and it’s really pretty simple.

    as with any if/then modifiers, you can have more than one. just make each seperate, you can also use negative qualifiers to exlude categories. the syntax is shown on the codex.

    good luck!

    That’s exactly what i was searching for!

    There is a plug in that does the same thing and more

    http://www.gudlyf.com/archives/2005/03/08/wordpress-plugin-category-visibility/

    Occording to its web page here is an improved (less bugs, more secure) version of the above plugin:
    http://tova.fena.se/2005/06/11/category-visibility/

    steadyvibe

    (@steadyvibe)

    I am having a problem with this plugin. It doesn’t exclude the posts from my monthly archives. I belive it also is causing a problem with my next and previous page tags. When i click to page 2 (eg: http://www.steadyvibe.com/page/2/), it does not display a previous page button even thought here are pages 3 (eg: http://www.steadyvibe.com/page/3/) and 4 (eg: http://www.steadyvibe.com/page/4/) after it?

    Has anyone had this problem?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘exclude category from search?’ is closed to new replies.