wordpress - WP循环,按自定义分类法分组,也仅使用帖子的主要分类法
问题描述
我有一个位于某个区域的场地循环。
我按类别(酒吧、餐馆等)对它们进行分组。
问题是我的一些场地有 2 个或更多类别。其中一个预计是主要的,但在我的循环中,它们出现的次数与所选类别的数量一样多。
这是我的代码:
<?php foreach ($venue_categories as $category):
$category_venues = new WP_Query([
'post_type' => 'venues',
'post_status' => 'publish',
'posts_per_page' => -1,
'paged' => false,
'orderby' => 'rand',
'order' => 'DESC',
'tax_query' => [
[
'taxonomy' => 'venues_tax',
'terms' => $category->term_id,
'field' => 'term_id'
],
],
'meta_query' => [
[
'key' => 'venue_is_closed',
'value' => 0
],
[
'key' => 'district',
'value' => $districtid
],
],
]);
if ($category_venues->have_posts()): ?>
<div class="col-12">
<h4>
<?php echo $category->name ?>
</h4>
</div>
<? while ($category_venues->have_posts()):
$category_venues->the_post();
get_template_part('template-parts/single/venue-list', 'round-third');
endwhile;
wp_reset_postdata();
endif;
endforeach; ?>
问题很简单——如何在我的循环中只使用主要类别?
解决方案
推荐阅读
- android - Android 在条件下启用/禁用微调器触摸侦听器
- android - 为什么当我定位错误(红线)时我的光标消失了?
- javascript - 使用 React(本地存储)仅显示一次 Popup
- visual-studio-code - VSCode 中错误的 TSX 三元标记块格式
- java - java.lang.RuntimeException:拍照时无法恢复活动 NullPointerException
- node.js - 如何使用 google-ads-node 从谷歌广告中获得印象(遇到一个问题;即使设置正确,客户 ID 也是无效的。)
- linux - grep 仅从 bash 获取特定部分的文本
- python - Python数组硬币排序
- html - 如何在 HTML 文件(外部文件或 HTML 文件内)中插入原始 Pug 代码
- performance - Haswell AVX/FMA 延迟测试比英特尔指南慢 1 个周期