Forums

Exclude Categories in Search Results (5 posts)

  1. Anonymous
    Unregistered
    Posted 3 years ago #

    Hi everyone,

    Here is a code that i have and for some reason my results are appearing in the following order:
    1st Page - 1 result
    2nd Page - 2 results
    3rd Page - 3 results

    Basically i want to exclude categories 9 and 17. Any clue as to why this could be happening.
    P.s: i dont want to use plugins

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if (in_category('9')) continue; ?>
    
    <?php if (in_category('14')) continue; ?>
    
    <?php the_title(); ?><br /><br />
    
    <?php endwhile;endif;?>
    
    <?php next_posts_link('&laquo; Old Updates') ?>
    
    <?php previous_posts_link('Latest Updates &raquo;') ?>
  2. rmk80
    Member
    Posted 3 years ago #

    Hi, see if this works for you:

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $s = get_query_var('s');
    query_posts("s=$s&cat=-9,-14&paged=$page");
    ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_title(); ?><br /><br />
    <?php endwhile;endif;?>
    <?php next_posts_link('&laquo; Old Updates') ?>
    <?php previous_posts_link('Latest Updates &raquo;') ?>
  3. Anonymous
    Unregistered
    Posted 3 years ago #

    Hey rmk80,

    your a freakin genius!

    Ive been trying to fix this for the past couple of days!

    5 Stars for you mate!

  4. fatihturan
    Member
    Posted 3 years ago #

    @rmk80: If i want to exclude all pages and some categories from search results then what i must do? Do you know a solution?

  5. Tammy Hart
    Member
    Posted 3 years ago #

    awesome! Just what I needed! Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic