这里有一个函数,我用来查询2个自定义分类法和2个术语:
在里面functions.php
// MULTIPLE TAXONOMY QUERY ALLOWANCE
function posts_search ($post_type,$taxonomies) { // $taxonomies should be an array (\'taxonomy\'=>\'term\', \'taxonomy2\'=>\'term2\')
foreach ($taxonomies as $key=>$value) {
$args=array(\'post_type\'=>$post_type,\'post__in\'=>$ids,$key=>$value);
unset($ids); $ids=array();
foreach($posts=get_posts($args) as $post) { $ids[]=$post->ID; }
if (empty($ids)) return false;
}
return $posts;
}
在一个
template file
:
$posts = posts_search (\'produtos\',array(\'prod-categoria\'=>$tt,\'prod-cols\'=>\'5-C-P-F-NF-P\'));
if($posts) {
foreach($posts as $post) {
if(get_post_meta($post->ID, "codigo_value", $single = true) != "") {
//here you can retrieve infos; i was interested in custom fields in my case
echo get_post_meta($post->ID, "codigo_value", $single = true);
}
}
}
我这里的两个自定义分类是
prod-categoria
和
prod-cols
我在寻找两个术语,其中一个来自变量
$tt
另一个呢
5-C-P-F-NF-P
.
希望这有帮助。