タクソノミー(カスタム投稿のカテゴリ) に登録しているカスタムフィールド を
条件分岐で表示する方法が分かりません。
入力があれば「titlehtml」(カスタムフィールド)を表示
なければ<?php wp_title( '' ); ?> | <?php bloginfo( 'name' ); ?>を表示させたいです。
現状、以下でカスタムフィールドの表示だけはできるのですが、
<title> <?$taxonomy = 'area_cat'; $term_slug = get_query_var('term');</title>$the_term = get_term_by('slug', $term_slug, $taxonomy); $term_id = $the_term->term_id; //タームのカスタムフィールドを取得するためのIDは「カスタム分類(タクソノミー)名_タームID」 $term_idsp = $taxonomy."_".$term_id; //タームではなく、カテゴリの場合は「category_カテゴリID」にする //$cat_id = $category->cat_ID; //$term_idsp = 'category_'.$cat_id; if(get_field('titlehtml', $term_idsp)){ echo get_field('titlehtml', $term_idsp); } ?>
以下の文とつなぐことができません
(値がなければ以下を表示)
以下のような感じで書いていますがエラーが出てしまいます。
<title> <?$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; $term_idsp = get_field( 'titlehtml', 'term_idsp'.$term_ID); $titlehtml = get_field('titlehtml', $term_idsp); } ?> <?php if( get_field(‘titlehtml’) ): ?> <?php echo $titlehtml; ?> <?php else : ?> <?php wp_title( '' ); ?> | <?php bloginfo( 'name' ); ?> <?php endif; ?> </title>よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/13 06:41
2020/11/13 06:52
2020/11/13 07:11
2020/11/13 07:28
2020/11/13 07:38
2020/11/13 07:50
2020/11/13 08:59
2020/11/16 00:18