【问题标题】:exclude children from taxonomy term从分类术语中排除儿童
【发布时间】:2016-03-24 20:48:20
【问题描述】:

您好,我有一个名为“support-team-doc”的自定义帖子类型和一个名为“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; ?>

我不知道我做错了什么。

【问题讨论】:

    标签: php wordpress custom-post-type children custom-taxonomy


    【解决方案1】:

    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; ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多