• On my search page there is a column that displays all the categories and the amount but when you click on the category it takes your to the archive page. What I am trying to achieve is that when you click on the “news” category for example it would only display results from the news category.

    Not entirely sure on the best way of doing this would the search term & category have to be appended into the url and then do a page refresh?

    This is how I am displaying the categories at the moment:

    <ul class="categories">
          <?php
          $args = array (
            'echo' => 0,
            'show_count' => 1,
            'title_li' => '',
            'depth' => 1
          );
          $variable = wp_list_categories($args);
          $variable = str_replace ( "(" , "<span>", $variable );
          $variable = str_replace ( ")" , "</span>", $variable );
          echo $variable;
          ?>
     </ul>

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    wp_list_categories() should be outputting URLs such as example.com/category/news/ (or example.com?cat=12 without permalinks), which should lead to a category archive page (typically the category.php template)) of only posts in the news category. If you are getting different results your theme or one of your plugins is altering the default behavior. To get normal behavior back, you best approach is to find the offending code and alter its operation.

Viewing 1 replies (of 1 total)
  • The topic ‘Filter search results from categories’ is closed to new replies.