“ tax_query”参数不适用于WP_Query
1 个回答
- 投票数
-
- 2012-04-16
tax_query
参数是数组数组 ,而不仅仅是数组.此:
'tax_query' => array( 'taxonomy' => 'video_type', 'terms' => 'episode', 'field' => 'slug', 'include_children' => true, 'operator' => 'IN' ),
应该是这样:
'tax_query' => array( array( 'taxonomy' => 'video_type', 'terms' => 'episode', 'field' => 'slug', 'include_children' => true, 'operator' => 'IN' ) ),
The
tax_query
parameter is an array of arrays, not just an array.This:
'tax_query' => array( 'taxonomy' => 'video_type', 'terms' => 'episode', 'field' => 'slug', 'include_children' => true, 'operator' => 'IN' ),
Should instead be this:
'tax_query' => array( array( 'taxonomy' => 'video_type', 'terms' => 'episode', 'field' => 'slug', 'include_children' => true, 'operator' => 'IN' ) ),
-
谢谢Chip.我很好奇Wordpress为何采用这种方式构建?Thanks Chip. I'm curious as to the reason why Wordpress has it built this way?
- 1
- 2012-04-16
- Josh Farneman
-
这样就可以使用布尔值执行多个税收查询.请参阅" **多种分类法处理**"部分下的链接的法典条目.So that multiple tax queries can be performed, using Booleans. See the linked Codex entry, under the "**Multiple Taxonomy Handling**" section.
- 5
- 2012-04-16
- Chip Bennett
-
对我来说就像一个魅力!谢谢男人,我在这头上撞墙了!Worked like a charm for me! Thanks man, I was banging my head off the wall on this one!
- 1
- 2014-11-23
- Charles Blackwell
-
我似乎无法弄清楚如何将其转换为url参数并使WP_Query实际使用它.它只是不断被忽略.I can't seem to figure out how to translate this into a url parameter and have it actually used by WP_Query. It just keeps getting ignored.
- 0
- 2018-04-12
- realgeek
-
谢啦!!这真的对我有帮助!Thanks man!! this really helps me!
- 0
- 2020-05-19
- Lai32290
我有一个称为"episode"的自定义帖子类型.附加到"情节"上的是我的自定义分类法,称为" video_type",其中包含两个术语:"奖金-足额"和"情节"; "episode"包含两个子术语" season-1"和" season-2"(将来会添加其他季节).我只想获取"情节"类型的最新帖子,但不包括"奖励不足"一词中的任何帖子.下面是我为此使用的代码:
如果"季节"术语之一中的帖子是最新的,则该查询将按预期工作,但是如果"奖金"中的帖子是最新的,则它将加载该查询.换句话说,我的"tax_query"参数似乎对查询没有影响.我是否无法正确格式化"tax_query"或缺少其他内容?
我还尝试过如下设置"tax_query":
但是我仍然得到相同的结果.