更新 2021 / 4 / 28

特定のtermを除外して、投稿に所属したターム名を表示

reg_matchi以降に除外したいタームのスラッグを記述する。
zyogai01・zyogai02を変更してください。複数指定可能なので、|で区切る

houselistはタクソノミー名


<?php $tax_name = 'houselist'; $terms = get_the_terms($post ,$tax_name ); if ( $terms && ! is_wp_error( $terms ) )  { $separator = ' / '; $output = ''; if ( $terms ) { foreach($terms as $term){ if(!preg_match('/zyogai01|zyogai02/', $term->slug)) { $output .= '<span  class="type_label">' . $term->name . '</span>' . $separator; } } echo trim( $output, $separator ); } } ?>