我有一个自定义的帖子类型,叫做portfolio 还有一种自定义分类法build-type (作为类别)
我正在尝试查询portfolio 发布人build-type ID,例如“Hotels”中的所有投资组合帖子(该分类法的ID=4)
// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, \'build_type_id\', true);
// run query
query_posts(array(
\'post_type\' => \'portfolio\',
\'showposts\' => -1,
\'tax_query\' => array(
\'taxonomy\' => \'build-type\',
\'terms\' => $buildType,
\'field\' => \'term_id\'
),
\'orderby\' => \'title\',
\'order\' => \'ASC\'
));
目前正在呼叫
all portfolio 而不仅仅是那些
build-type 身份证件
对于\'field\' => \'term_id\' 我应该使用term_id, tag_ID, id 还是别的什么?
有人知道如何让它工作吗?
提前感谢!
最合适的回答,由SO网友:Drew Gourley 整理而成
这不起作用的原因是因为“tax\\u query”需要是一个数组数组(我知道这很混乱)。
...
\'tax_query\' => array(
array(
\'taxonomy\' => \'build-type\',
...
这样您就可以将一些不同的规则组合在一起。
SO网友:mattberridge
Drew是对的,tax-query 需要是数组的数组
最终解决方案是:
// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, \'build_type_id\', true);
// run query
query_posts(array(
\'post_type\' => \'portfolio\',
\'showposts\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'build-type\',
\'terms\' => $buildType,
\'field\' => \'term_id\',
)
),
\'orderby\' => \'title\',
\'order\' => \'ASC\' )
);
在github上:
https://gist.github.com/1275191
谢谢