[英]Wordpress query_posts category dropdown filter
我正在为wordpress设计一个下拉菜单,该菜单从帖子中过滤出不同的类别。 我目前正在使用query_posts函数,如下所示:
query_posts( array('category__and'=>array($_GET['operation'],$_GET['type'])));
get $_GET['operation']
和$_GET['type']
显然是通过表单下拉菜单中的get参数传递的。
当我将2个值传递给查询正确运行的表单时,它将显示所选正确类别内的帖子,一切都很好。
当我没有定义任何get值的形式时,麻烦就来了,所以从url获得的结果就像是空的。
Example:
operation=4
type=2
它可以正确运行。
Trouble:
operation=""
type=2
查询或任何我看不到的中断,并显示没有结果。
我希望是否有任何方法可以检查任何值是否为空并将其从数组中排除? 任何类似:
query_posts( array('category__and'=>array(
if($_GET['operation']!=""){
$_GET['operation'],
}
$_GET['type']
))
);
请帮忙!
这样的事情应该可以满足您的需求。
$args = array();
if (!empty($_GET['operation']))
$args[] = $_GET['operation'];
if (!empty($_GET['type']))
$args[] = $_GET['type'];
if (!empty($args))
query_posts( array('category__and'=>$args));
else
query_posts();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.