サポート » プラグイン » Advanced Custom Fieldの追加フィールドを出力したい

  • 解決済 dgark

    (@dgark)


    タクソノミー : 予約状況(スラッグ名 : tour_status)

    ACFで、
    ・フィールドグループ1 : 「予約状況」というラベルに、フィールドタイプ「タクソノミー」、タクソノミーに「予約状況」 を指定

    ・フィールドグループ2 : タクソノミー「予約状況」に、カラーピッカーフィールド(status_color)を追加

    という設定をしています。

    このカラーピッカーフィールド(status_color)の値を、以下のソースで出力させることができず困っています。ご教示願います。

     <?php
          // ループ
            if ( $the_query->have_posts() ):
            while ( $the_query->have_posts() ): $the_query->the_post();
          ?>
     
    
    ~
    
    <?php 
      $terms = wp_get_object_terms($post->ID, 'tour_status'); // タクソノミースラッグ
      foreach($terms as $term){
        $term_color = get_field('status_color','tour_status_'.$term_id); // 追加したカスタムフィールドの取得
        echo $term_color ; // タームの値を表示
      }
      var_dump( $terms );
    ?>
    
    ~
    
    <?php endwhile; endif; ?>

    $term_color = get_field(‘status_color’,’tour_status_’.$term_id); // 追加したカスタムフィールドの取得

    で取得できていないようなので、記述方法が間違っているのでしょうか。

    参考
    https://hirashimatakumi.com/blog/1365.html

    • このトピックはdgarkが3年、 4ヶ月前に変更しました。
    • このトピックはdgarkが3年、 4ヶ月前に変更しました。
2件の返信を表示中 - 1 - 2件目 (全2件中)
  • こんにちは

    ここではないでしょうか?

    $term_color = get_field('status_color','tour_status_'.$term_id);

    $term_color = get_field('status_color','tour_status_'.$term->term_id);

    トピック投稿者 dgark

    (@dgark)

    これで取得できました。
    ありがとうございます。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「Advanced Custom Fieldの追加フィールドを出力したい」には新たに返信することはできません。