简体   繁体   English

Wordpress Pods:如何只获取包含文章的(子)类别

[英]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:要可视化所需的结果:

  • subcategory A (10 articles linked)子类别 A(已链接 10 篇文章)
  • subcategory B (0 articles linked) <- I do not want this one子类别 B(链接 0 篇文章)<- 我不想要这个
  • subcategory C (1 article linked)子类别 C(已链接 1 篇文章)

So for my pods , I have the following: (all Advanced Content Type)所以对于我的 pods ,我有以下内容:(所有高级内容类型)

Category pod :类别吊舱

  • Text field: slug文本字段:slug
  • Relational field: category_relation (this field is only filled when the category is a subcategory)关系字段:category_relation(该字段仅在类别为子类别时才填写)

Article pod :文章荚

  • Relational field: category关系领域:类别

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM