问题描述
我有三个相关的分类法 tax1 =品牌,tax2 =正文,tax3 =品牌,正文
tax3是前两个的组合
我想显示从'make'存档页面到所有带有帖子的'make-body'存档页面的链接(不显示指向空白存档页面的链接)
然后,我想在“正文”存档页面上进行相反的操作。
所以我需要部分匹配'向我展示一个不为空的'make-body'子数组,并匹配当前存档页面的'body'或'make'
蛋糕上的奶油是,如果我可以在链接后面加上一个可用的“ make-body”计数。 我不是PHP方面的专家(轻描淡写),但是我可以看到它返回了“ make-body”段列表和当前存档页面的段列表。
努力筛选“ make-body”结果,以仅显示与页面相关的结果。
我假设我然后必须插入数组并将URL的其余部分添加到段中...
感谢您的任何帮助(这是第一次发布,因此,我确定我在所有礼节中都受过粗鲁的对待!)
到目前为止,我有以下内容将构建一个数组(从另一个SO问题中借用)
$terms = get_the_terms( $post->ID,'body' );
foreach ( $terms as $term ) {
}
$filter =($term->slug);
$termArgs = array(
'post_status' => 'publish','orderby' => 'name','order' => 'ASC','post_type' => 'page','tax_query' => array(
'relation' => 'AND',array(
'taxonomy' => 'make-body','field' => 'term_id','terms' => get_terms( 'make-body',array( 'hide_empty' => true,'fields' => 'slugs')),'operator' => 'IN',),array(
'taxonomy' => 'body','terms' => $filter,'field' => 'slug'
)
)
);
print_r($termArgs);
解决方法
我设法在匹配分类标准的第一部分的基础上使其起作用。现在,这给了我所有以父类法术语开头的术语,并带有指向存档页面的链接。
$categories = array();
$names = array();
$reg = '/^'. ($term->slug) .'/';
$category_list_items = get_terms( 'your-taxonomy',array( 'hide_empty' => true,));
foreach($category_list_items as $category_list_item){
if(! empty($category_list_item->slug) ){
$categories[] = $category_list_item->slug;
$names[] = $category_list_item->name;
}
}
foreach ($categories as $key=>$category) {
if(preg_match($reg,$category)){
echo "<a href=/absolute-path/".$category ."/>";
echo $names[$key] . " items</a> |";
$args = array( 'post_type' => 'listing','posts_per_page' => 100,'your-taxonomy' => $category,'orderby' => 'rand' );
}
}