使用WordPress过滤搜索结果

我正在尝试设置一个包含两列的” 搜索结果” 页面。第一列将显示除一个(Galleries)以外的所有类别的结果, 第二列将仅显示Galleries类别。
query_posts()只是重置我的结果。这就是我到目前为止所得到的。破碎:

< ?php $s = get_query_var('s'); query_posts('s=' . $s . '& cat=164'); ?> < ?php // First Loop ?> < div class="contentLeft"> < ul class="postListSmall related"> < ?php while (have_posts()) : the_post(); ?> [do stuff] < ?php endwhile; ?> < ?php // Second Loop ?> < ?php query_posts('cat=-164'); ?> < ?php rewind_posts(); ?> < ?php while (have_posts()) : the_post(); ?> [do stuff] < ?php endwhile; ?> < ?php else : ?> [do stuff] < ?php endif; ?>

该怎么办?
#1【使用WordPress过滤搜索结果】我知道这是一篇过时的文章, 但是我遇到了类似的问题, 并想分享一下:
  1. 你正在创建一个查询, 然后调用第二个查询, 但随后尝试回退该查询。倒带功能不是这样的。看一下倒带文档。你还说:
query_posts()只是重置我的结果。
那么, 为什么在新查询之后立即调用rewind函数呢?另外, 如果你要重置结果, 那么为什么它完全是另一个查询?这个:
$s = get_query_var('s'); query_posts('s=' . $s . '& cat=164');

与此不同:
< ?php query_posts('cat=-164'); ?> < ?php rewind_posts(); ?>

为了获得不同类别的2列结果, 我执行了以下操作:仅使用一个循环, 不使用rewind, 在循环的if语句中使用get_the_category, 例如:
< ?php $s = get_query_var('s'); query_posts('s=' . $s . '& cat=164'); while (have_posts()) : the_post(); foreach(get_the_category() as $category){ if($category-> name == "category name"){ //Concatenate to the left div } else { //concatenate to the right div } ?>

希望这可以帮助。

    推荐阅读