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

質問編集履歴

2

$titlehtml = get_field('titlehtml', $term_idsp);を追加しました

2020/11/13 08:57

投稿

raise
raise

スコア9

title CHANGED
File without changes
body CHANGED
@@ -38,8 +38,9 @@
38
38
  $term_slug = get_query_var('term');
39
39
  $the_term = get_term_by('slug', $term_slug, $taxonomy);
40
40
  $term_id = $the_term->term_id;
41
- $term_idsp = $taxonomy."_".$term_id;
41
+ $term_idsp = $taxonomy."_".$term_id;
42
42
  $term_idsp = get_field( 'titlehtml', 'term_idsp'.$term_ID);
43
+ $titlehtml = get_field('titlehtml', $term_idsp);
43
44
  } ?>
44
45
  <?php if( get_field(‘titlehtml’) ): ?>
45
46
  <?php echo $titlehtml; ?>

1

マークダウンこちらで合っていますか

2020/11/13 08:57

投稿

raise
raise

スコア9

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,22 @@
7
7
 
8
8
  現状、以下でカスタムフィールドの表示だけはできるのですが、
9
9
  <title>
10
- <?$taxonomy = 'area_cat'; $term_slug = get_query_var('term'); $the_term = get_term_by('slug', $term_slug, $taxonomy); $term_id = $the_term->term_id; $term_idsp = $taxonomy."_".$term_id; if(get_field('titlehtml', $term_idsp)){echo (get_field('titlehtml', $term_idsp));} ?>
10
+ <?$taxonomy = 'area_cat';
11
+ $term_slug = get_query_var('term');
12
+
13
+ $the_term = get_term_by('slug', $term_slug, $taxonomy);
14
+ $term_id = $the_term->term_id;
15
+
16
+ //タームのカスタムフィールドを取得するためのIDは「カスタム分類(タクソノミー)名_タームID」
17
+ $term_idsp = $taxonomy."_".$term_id;
18
+
19
+ //タームではなく、カテゴリの場合は「category_カテゴリID」にする
20
+ //$cat_id = $category->cat_ID;
21
+ //$term_idsp = 'category_'.$cat_id;
22
+
23
+ if(get_field('titlehtml', $term_idsp)){
24
+ echo get_field('titlehtml', $term_idsp);
25
+ } ?>
11
26
  </title>
12
27
 
13
28