• maestro42

    (@maestro42)


    is there a way to limit the search function (using wp 1.5) – on the sidebar.php page to only search through certain categories ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter maestro42

    (@maestro42)

    bump?

    Thread Starter maestro42

    (@maestro42)

    anyone ?

    Per https://www.ads-software.com/support/topic/24655#post-191904 I ask again:
    A search like my https://www.richardc020.com/index.php?cat=6&s=njtransit still lists results not in cat=6. Why and how to fix.

    Reply.

    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 stack the qualifiers to return results that are IN one category and NOT in another. using the exclusion syntax as shown on the codex.

    good luck!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘limit search to certain category’ is closed to new replies.