如果您想过滤结果,您可能希望查看AJAX解决方案(如果您处理的潜在数千个结果)或使用Javascript/jQuery切换基于结果的可见性他们的后期型。一个简单的解决方案就是像这样使用jQuery。
在你的search.php模板:
<form action="" method="POST">
<input class="radioToggle" type="radio" name="post_type" value="type1" />Filter 1<br/>
<input class="radioToggle" type="radio" name="post_type" value="type2" />Filter 2<br/>
<input class="radioToggle" type="radio" name="post_type" value="type3" />Filter 3<br/>
</form>
<div class="result type1">
result of type 1....
</div>
<div class="result type2">
result of type 2....
</div>
<div class="result type2">
result of type 2....
</div>
<div class="result type3">
result of type 3....
</div>
<div class="result type3">
result of type 3....
</div>
<div class="result type3">
result of type 3....
</div>
<script type="text/javascript">
jQuery(document).ready(function($))
{
$(".radioToggle").click(function()
{
$(".result."+$(this).attr("value")).css("display", "block");
$(".result:not(."+$(this).attr("value")+")").css("display", "none");
});
});
</script>
这是未经测试,我会亲自完全避免在飞行中这样做。我个人认为,应该事先使用PHP过滤搜索结果,而不是事后使用Javascript。但是,如果这对您的用户界面是必要的,那么这应该有助于您开始。
请记住,为了使用这种方法,jQuery将需要安装或通过您的主题排队。
http://stackoverflow.com/questions/8177768/wordpress-custom-search-by-post-type – maiorano84 2012-07-10 20:22:35
嗨,感谢您的链接,但我认为这涉及如何筛选结果,当我搜索的东西。我想要做的是做一个搜索,然后有单选按钮来过滤用户可以使用的结果。不要单击一个单选按钮,然后重复搜索。它更像是一个实时过滤器。也许按过滤器确实刷新搜索,不确定。我猜这些辐射按钮可能也是标签! – Redwall 2012-07-11 10:26:47