投稿に属する特定のタームの子タームのみを取得する方法
-
下記フォーラムを試しましたが、実装できなかったため、どなたかお分かりになる方ご教授いただけますと幸いです。
https://ja.wordpress.org/support/topic/%E7%89%B9%E5%AE%9A%E3%81%AE%E3%82%BF%E3%83%BC%E3%83%A0%E3%82%92%E9%99%A4%E5%A4%96%E3%81%97%E3%81%A6%E5%8F%96%E5%BE%97%E3%81%97%E3%80%81%E5%A4%89%E6%95%B0%E3%81%AB%E6%A0%BC%E7%B4%8D%E3%81%97%E3%81%9F/記事詳細ページにて、その記事に属するタームを取得していますが、ID2のタームは表示させたくないので「’exclude’ => 2」でID指定しています(※’exclude’ => ‘2’としてみても挙動は変わらず)。
取得したタームはカスタムフィールドに登録している画像を表示させるという形で、問題なく表示はされていますが、除外のみ反応しません。<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php //$terms = get_the_terms($post->ID, 'category'); $terms = wp_get_post_terms( $post->ID, 'category', array( 'exclude' => 2 ) ); if ($terms) : foreach ($terms as $term) { $terms_id = esc_html($term->term_id); $terms_name = esc_html($term->name); // タームの名前を取得 $post_id = 'category_'. $terms_id; // タームのIDを取得 $terms_imgid = get_field('series_tag', $post_id); $terms_img = wp_get_attachment_image_src($terms_imgid, 'full')[0]; if($term->parent) //子タームがあった場合のみ表示させる echo '<img src="'. $terms_img .'" alt="'. $terms_name .'">'; } endif; ?> <?php the_content(); ?> <?php endwhile; ?> <?php endif; ?>
宜しくお願い致します。
4件の返信を表示中 - 1 - 4件目 (全4件中)
4件の返信を表示中 - 1 - 4件目 (全4件中)
- トピック「投稿に属する特定のタームの子タームのみを取得する方法」には新たに返信することはできません。