2017-11-08 8 views
0

投稿タイプのカテゴリを表示してそのカテゴリ内の投稿を出力しようとしていますが、除外する別の分類があります。このコードは、特定の投稿タイプに登録されているすべての分類と用語を表示しています。カテゴリー別に分類された投稿タイプループから分類を除外する

除外しようとしている2番目の分類法は「製造元」と呼ばれ、複数の投稿タイプに登録されています。私は 'operator' => 'NOT EXISTS'や、あなたが以下で見ているものだけをやってみました。

<?php 
$post_type = 'equipment'; 
$taxonomies = get_object_taxonomies(array('post_type' => $post_type)); 
foreach($taxonomies as $taxonomy) : 
$terms = get_terms($taxonomy); 
foreach($terms as $term): 
if ($term->slug == 'manufacturer') 
continue; 
    ?> 

    <div class="row"> 
    <div class="col-xs-12"> 
     <h2><?php echo $term->name; ?></h2> 
    </div> 

    <div class="col-xs-12"> 
    <?php 
    $args = array(
      'post_type' => $post_type, 
      'posts_per_page' => -1, 
      'tax_query' => array(
       array(
        'taxonomy' => $taxonomy, 
        'field' => 'slug', 
        'terms' => $term->slug, 
       ) 
      ) 

     ); 
    $posts = new WP_Query($args); 
if($posts->have_posts()): while($posts->have_posts()) : $posts->the_post(); ?> 
<h4><a href="<?php echo get_permalink(); ?>" title="Read more about <?php echo get_the_title(); ?>"><?php echo get_the_title(); ?></a></h4> 
<?php endwhile; endif; ?> 
</div> 
</div>  
<?php endforeach; 
endforeach; ?> 

答えて

0

$args = array(
    'post_type' => array('equipment'), 
    'posts_per_page' => -1, 
    'order' => 'DESC', 
    'tax_query' => array(
     array(
      'taxonomy' => 'manufacturer', 
      'field' => 'slug', 
      'operator' => 'NOT IN', 
     ), 
    ), 
); 
$query = new WP_Query($args); 
関連する問題