嗨,我有一个名为"支持团队文档"的自定义帖子类型和一个称为"support_team_docs"的自定义分类法,其类别如下:
Support Teams Group
-- Accounts
-- IT
-- Marketing
-- Risk & Compliance
每个类别都有许多员额;我不希望来自子类别的帖子显示在任何类别页面上;atm子类别"账户、it、营销、风险合规"中的任何帖子都显示为:"支持团队组";我尝试过以下几种:
<?php
$termsTextarea = get_queried_object();
$args = array(
'post_type' => 'support-team-doc',
'tax_query'=>
array(
'taxonomy' => 'support_team_docs',
'field' => 'slug',
'terms' => $termsTextarea->slug,
'include_children' => false,
),
);
$query1 = new WP_Query( $args );
while ( $query1->have_posts() ) : $query1->the_post();
get_template_part( 'content', 'support_team_docs' );
endwhile; ?>
我不知道我做错了什么。
tax_query是一个多维数组。。。当前代码中缺少一个数组元素。试试这个:
<?php
$termsTextarea = get_queried_object();
$args = array(
'post_type' => 'support-team-doc',
'tax_query'=>
array(
array(
'taxonomy' => 'support_team_docs',
'field' => 'slug',
'terms' => $termsTextarea->slug,
'include_children' => false
)
)
);
$query1 = new WP_Query( $args );
while ( $query1->have_posts() ) : $query1->the_post();
get_template_part( 'content', 'support_team_docs' );
endwhile; ?>