我想统计一下同时有3种不同分类法的帖子数量。我使用的代码是:
$products = get_posts(array(
\'post_type\' => \'products\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'collection\',
\'field\' => \'slug\',
\'terms\' => array($current_collection),
\'operator\' => \'IN\'
),
array(
\'taxonomy\' => \'type\',
\'field\' => \'slug\',
\'terms\' => array($current_type),
\'operator\' => \'IN\'
),
array(
\'taxonomy\' => \'color\',
\'field\' => \'slug\',
\'terms\' => array($current_type),
\'operator\' => \'IN\'
)
)
));
$countpost = count($products);
当
colors 和
type 我要查找的分类术语不存在。。。
如果collection 不存在,计数为0
如果type 不存在,它返回具有指定集合和颜色的帖子
它是color 不存在,它返回具有指定集合和类型的帖子
我想说的是,由于和的关系,如果其中一个项不存在,计数应该始终为0,而不是基本上忽略该项,只考虑其他两个项。。。
我做错什么了吗?我怎样才能修复它?
非常感谢!
SO网友:Md Toufiqul Islam
请按如下方式再次尝试删除运算符和关系参数:下面是一个有用的链接http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/
$products = get_posts(array(
\'post_type\' => \'products\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'collection\',
\'field\' => \'slug\',
\'terms\' => array($current_collection)
),
array(
\'taxonomy\' => \'type\',
\'field\' => \'slug\',
\'terms\' => array($current_type)
),
array(
\'taxonomy\' => \'color\',
\'field\' => \'slug\',
\'terms\' => array($current_type)
)
)
));
$countpost = count($products);