複数のタクソノミーを記載方法
タクソノミーアーカイブ(taxonomy.php)で複数のタクソノミーから記事一覧を取得したい場合の記載方法
<?php
$term_var = get_the_terms( $post->ID, '〇〇〇' );
$term_var2 = get_the_terms( $post->ID, '●●●' );
$postQuery = new WP_Query();
$param = array(
'posts_per_page' => '4',
'post_type' => 'post',
'paged' => $paged,
'post__not_in' => array(get_the_ID()),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => '〇〇〇',
'field' => 'slug',
'terms' => $term_var[0] ←いらない
),
array(
'taxonomy' => '●●●',
'field' => 'slug',
'terms' => $term_var2[0] ←いらない
)
)
);
$postQuery->query($param);
?>
<li>〜</li>
<?php if( $postQuery->have_posts() ) :?>
<?php while( $postQuery->have_posts() ):$postQuery->the_post(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
下記エラー?が出たのでタームの指定をコメントアウトしたら消えた
Notice: Trying to access array offset on value of type bool in...
【参考】複数のタクソノミーを指定して記事一覧を表示 | 大阪 ホームページ制作 株式会社TREVOの技術ブログ