我有这样的自定义分类法和分类:
products_categories
cat-1
cat-1
post-1 post-2 post-3
cat-2
post-1 post-2 post-3
cat-3
post-1 post-2 post-3
cat-2
cat-1
post-1 post-2 post-3
cat-2
post-1 post-2 post-3
cat-3
post-1 post-2 post-3我想创建一个存档页面:
这是我的档案:
第一:
$args = array(
'type' => 'products',
'taxonomy' => 'products_categories',
$categories = get_categories( $args );第二:
<? foreach ( $categories as $category ):
$cat_id = $category->term_id;
$cat_name = $category->cat_name;
?>第三:
<?php
$cats_id= array();
foreach ( $sub_categories as $sub_category ) :
$cats_id[]=$sub_category->term_id;
endforeach;
$args = array(
'posts_per_page' => -1,
'orderby' => 'rand',
'post_type' => 'products',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'products_categories',
'field' => 'id',
'terms' => $cats_id,
),
));
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
?>没什么大不了的。我得到了所有的职位,这些子类别的父类;
现在我想在最后一节中得到帖子的分类id。
发布于 2016-09-15 15:43:59
目前员额的职类如下:
get_the_terms()这将返回附加到post的类别数组。
https://stackoverflow.com/questions/39514703
复制相似问题