[英]Wordpress Pods: How to only get (sub)categories with articles in it
I am trying to get all subcategories which have articles linked to it.我正在尝试获取所有链接到它的文章的子类别。
To visualize the needed result:要可视化所需的结果:
So for my pods , I have the following: (all Advanced Content Type)所以对于我的 pods ,我有以下内容:(所有高级内容类型)
Category pod :类别吊舱:
Article pod :文章荚:
I have this query, which works, but it does not skip the subcategories who has no articles in it.我有这个查询,它有效,但它不会跳过没有文章的子类别。
$subcategories = pods( 'category',
array( 'where' => "category_relation.slug = 'Top Category"
) );
I know I should do a left join, but I do not see how to get that working because I can only select one pod type at once.我知道我应该做一个左连接,但我不知道如何让它工作,因为我一次只能选择一种 pod 类型。
Have anyone experience with this type of getting pods data?有没有人有过这种获取 pods 数据的经验?
Note: I asked this question on the Pods forum too, but did not get any response.注意:我也在 Pods 论坛上问过这个问题,但没有得到任何回应。 On SO I will reach more people I think and update the forum post on Pods.io with the best answer.在 SO 上,我会联系更多我认为的人,并用最佳答案更新 Pods.io 上的论坛帖子。
Have you tried 'where' => 'category_relation.slug = "Top Category" AND 0 < tt.count'
yet?你试过'where' => 'category_relation.slug = "Top Category" AND 0 < tt.count'
了吗?
Also, if you pass any string into the 'where' that's a $variable, definite be sure to sanitize it first ( pods_sanitize( $variable )
, $wpdp->prepare( "category_relation.slug = %s", $variable )
, etc..)此外,如果您将任何字符串传递到 $variable 的“where”中,请务必先对其进行清理( pods_sanitize( $variable )
, $wpdp->prepare( "category_relation.slug = %s", $variable )
,等等..)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.