抱歉把标题弄乱了。不知道如何更好地描述它。我想展示所有的商店,首先按他们的分类,然后,在里面,按他们的位置排序。
我有自定义邮政类型的“商店”,两个定制分类“商店类别”,“商店的位置”。
例如,我希望它能显示:
东京
东京
鞋,电子学,(.)-分类学#1
伦敦,东京,(.)-分类学#2
01店,(.)-自定义邮政类型
到目前为止还能用一个分类法来显示。虽然效果不错,但我还需要一个水平。
'shop',
'tax_query' => array(
array(
'taxonomy' => 'shop_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo ''.$custom_term->name.'';
while($loop->have_posts()) : $loop->the_post();
echo ''.get_the_title().'
';
endwhile;
}
}
?>提前谢谢你的指示。
发布于 2018-03-08 09:01:22
首先要有一个类别列表和一个位置列表。然后循环遍历每个类别。在每个类别循环中,遍历具有当前类别和当前位置的位置列表和查询帖子,并输出列表:
$categories = get_terms( array(
'taxonomy' => 'shop_category',
) );
$locations = get_terms( array(
'taxonomy' => 'shop_location',
) );
foreach ( $categories as $category ) {
echo '' . $category->name . '';
foreach ( $locations as $location ) {
$shops = new WP_Query( array(
'post_type' => 'shop',
'tax_query' => array(
array(
'terms' => $category->term_id,
'taxonomy' => 'shop_category',
),
array(
'terms' => $location->term_id,
'taxonomy' => 'shop_location',
),
),
) );
if( $shops->have_posts() ) {
echo '' . $location->name . '';
while ( $shops->have_posts() ) : $shops->the_post();
echo '' . get_the_title() . '
';
endwhile;
}
wp_reset_postdata();
}
}https://wordpress.stackexchange.com/questions/296176
复制相似问题