Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress计数错误_Wordpress_Counting - Fatal编程技术网

Wordpress计数错误

Wordpress计数错误,wordpress,counting,Wordpress,Counting,我想做的是: 这些帖子可以分为A类或B类。我想做一个档案,统计有多少帖子被归为A类,有多少帖子被归为B类,以及总数 问题是: 我的代码在A类中的数量相当于12篇文章。在B类中的数量是5篇。但在这两类中的数量都是12篇 为什么? 我的代码: $posts_a = new WP_Query('cat=5&category__and=30'); $count_a = $posts_a->post_count; //gives 12 $posts_b = new WP_Query('ca

我想做的是: 这些帖子可以分为A类或B类。我想做一个档案,统计有多少帖子被归为A类,有多少帖子被归为B类,以及总数

问题是: 我的代码在A类中的数量相当于12篇文章。在B类中的数量是5篇。但在这两类中的数量都是12篇

为什么?

我的代码:

$posts_a = new WP_Query('cat=5&category__and=30');
$count_a = $posts_a->post_count;
//gives 12

$posts_b = new WP_Query('cat=5&category__and=29');
$count_b = $posts_b->post_count;
//gives 5

$posts_all = new WP_Query('cat=5');
$count_all = $posts_all->post_count;
//gives 12. It should be at least 12+5.
我不想只求A+B的和,我想知道哪里错了


谢谢

在查看您的查询时,您看起来并不是只有两个类别。 据我所知,有三类,A、B和C

从你的查询和结果中我可以看到,A类和B类有12个帖子,A类和C类有5个帖子

您还错误地使用了类别_uu,这可能是造成混淆的原因

您能告诉我您正在搜索的两个类别ID是什么吗?在你提到这些问题后,我会发布它们

编辑:您可能需要:

$posts_a = new WP_Query(array('category__and'=>array(5,30),'posts_per_page'=>-1));
$count_a = $posts_a->post_count;

$posts_b = new WP_Query(array('category__and'=>array(5,29),'posts_per_page'=>-1));
$count_b = $posts_b->post_count;

$posts_all = new WP_Query('cat=5&posts_per_page=-1');
$count_all = $posts_all->post_count;

另外,这可能是一个显而易见的答案,我不知道你的类别结构,但29是一个30人的儿童类别吗?

谢谢你的回答。是的,该网站可以有很多类别(如ID:1、2、3、4、5、6…),但所有这些类别都必须归类为a(ID 30)或B(ID 29)。ID为5的档案应该显示:1)ID为5的帖子也被归类为A(ID为30)。2) ID为5的帖子也被归类为B(ID为29)。3) 所有ID为5的帖子(应该包括分类为A、B的帖子,甚至是我忘记分类为A或B的帖子)。ID 5和A将返回我12。ID 5和B将返回我5。“所有ID 5都返回12给我。”利奥编辑了我的答案。看看,试试这个!它给了我同样的数额(第一次12英镑,第二次5英镑)。对我来说没有意义的是计算总数。你确定没有任何重叠的帖子吗?尝试
$posts\u c=新的WP\u查询(数组('category\u and'=>array(5,29,30))
在WP\u查询数组中添加
每页的posts\u
,然后重试<代码>$posts\u all=new WP\u查询('cat=5&posts\u per\u page=-1')实际上,在所有WP_查询中都使用它。看看我编辑的答案,你的帖子有重叠吗?也就是说,你是说,一篇文章同时在a和B两个类别中?不,谢谢!