teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2021/10/03 14:48

投稿

CHERRY
CHERRY

スコア25234

answer CHANGED
@@ -4,4 +4,18 @@
4
4
 
5
5
  ----
6
6
 
7
- [get_the_terms](https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/get_the_terms) や [wp_get_post_terms](https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/wp_get_post_terms) で、投稿IDのタームを取得して、[array_search](https://www.php.net/manual/ja/function.array-search.php) で「指定のターム」が含まれているか検索して、検索結果の条件で振り分ける感じでしょうか。
7
+ [get_the_terms](https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/get_the_terms) や [wp_get_post_terms](https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/wp_get_post_terms) で、投稿IDのタームを取得して、[array_search](https://www.php.net/manual/ja/function.array-search.php) で「指定のターム」が含まれているか検索して、検索結果の条件で振り分ける感じでしょうか。
8
+
9
+ ----
10
+ (追記)
11
+
12
+ たとえば、表示しているテンプレートの中で
13
+ ```
14
+ $term_lists = wp_get_post_terms($post->ID, 'event-tag', array("fields" => "slug"));
15
+ if( is_array($term_lists) && array_search('closed', $term_lists) ){
16
+ // closed タームがある時の画面出力
17
+ } else {
18
+ // closed タームがない時の画面出力
19
+ }
20
+ ```
21
+ のような感じでしょうか。