mat*_*dge 4 wordpress taxonomy custom-taxonomy
我有一个名为自定义的帖子类型portfolio和一个名为build-type(作为类别)的自定义分类
我正在尝试portfolio通过build-typeID 查询帖子,例如"酒店"中的所有投资组合帖子(对于该分类,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'
));
Run Code Online (Sandbox Code Playgroud)
目前它正在调用所有 portfolio帖子,而不仅仅是那些有build-typeID的帖子
对于'field' => 'term_id'我应该使用term_id,tag_ID,id或其他什么东西?
任何人都知道如何使这个工作?
提前致谢!
mat*_*dge 15
我在以下帮助下解决了这个问题:https://wordpress.stackexchange.com/questions/30476/query-posts-by-custom-taxonomy-id
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' )
);
Run Code Online (Sandbox Code Playgroud)
在github这里:
https://gist.github.com/1275191
| 归档时间: |
|
| 查看次数: |
36991 次 |
| 最近记录: |