2016-08-25 10 views
0

「商品」というカスタムの投稿タイプと、「成分」という投稿タイプ内のカスタム分類を作成しました。ACFリピーターフィールド表示

「原料-INCI」と呼ばれるリピーターフィールドと、「成分-INCI-group」のサブフィールドを追加しました。これはタクソノミー「成分」の値を呼び出します。

カスタムリピータフィールドスクリーンショット:

Click to view Custom Repeater Field Screenshot

各製品は、多くの食材を持って、私は、製品の選ばれた成分のリストを表示したいと思います。

<?php 
 
/** 
 
PostType Page Template: Product 
 
*/ 
 

 
get_header(); ?> 
 

 
\t <div id="b_primary" class="b_content-area"> 
 
\t \t <main id="b_main" class="b_site__main" role="main"> 
 

 
\t \t <?php while (have_posts()) : the_post(); ?> 
 

 
<!-- START product information --> 
 
      
 
      <div class="toptext">If you have any enquiries, please click here to contact us.</div> 
 
      <div class="toptext">Please ensure you include all the products information that you wish to enquire about.</div> 
 
      <div class="tableproduct"> 
 
      <table> 
 
    <tr> 
 
     <th><div class="tabletitle">PRODUCT NAME</div></th> 
 
    <th><div class="tableresult"><?php wp_title(); ?></div></th> 
 
    </tr> 
 
    <tr> 
 
    <td><div class="tabletitle">PRODUCT DESCRIPTION</div></td> 
 
    <td><div class="tableresult"><?php the_field('product_description'); ?></div></td> 
 
    </tr> 
 
    <tr> 
 
    <td><div class="tabletitle">BRAND</div></td> 
 
    <td><div class="tableresult"><?php the_field('brand'); ?></div></td> 
 
    </tr> 
 
    <tr> 
 
    <td><div class="tabletitle">BARCODE</div></td> 
 
    <td><div class="tableresult"><?php the_field('barcode'); ?></div></td> 
 
    </tr> 
 
    <tr> 
 
    <td><div class="tabletitle">Ingredients (INCI Name)<br><div class="tablesubtitle">NOTE: Ingredients are listed in decreasing order of quantity.</div></div></td> 
 
    <td><div class="tableresult"> 
 

 
\t \t <?php 
 

 
// check if the repeater field has rows of data 
 
if(have_rows('ingredients-INCI')): 
 

 
    \t // loop through the rows of data 
 
    while (have_rows('ingredients-INCI')) : the_row(); 
 

 
     // display a sub field value 
 
     the_sub_field('ingredients-INCI-group'); 
 

 
    endwhile; 
 

 
else : 
 

 
    // no rows found 
 

 
endif; 
 

 
?> 
 

 
     </div></td> 
 
    </tr> 
 
    <tr> 
 
    <td><div class="tabletitle">Fragrance Ingredients (INCI Name)<br><div class="tablesubtitle">NOTE: Fragrance Ingredients are those which require listing under EC648/2004 on detergents.</div></div></td> 
 
    <td><div class="tableresult"> 
 
\t \t 
 
\t \t RESULTS HERE 
 
\t \t 
 
</div></td> 
 
    </tr> 
 
</table> 
 
       <div class="tabletitleother">OTHER INFORMATION</div> 
 
       <div class="tableotherresults">The above formulation is for products manufactured between <?php the_field('date_from'); ?> and <?php the_field('date_to'); ?></div> 
 
       <div class="tableyellow">INCI/CAS/Ingredient information CLICK HERE or HERE</div> 
 
      </div> 
 
      
 
<!-- END product information --> 
 

 
\t \t <?php endwhile; // End of the loop. ?> 
 

 
\t \t </main><!-- #b_main --> 
 
\t </div><!-- #b_primary --> 
 

 
<?php get_sidebar(); ?> 
 
<?php get_footer(); ?>

このコードは出力を破るようだ:ここに私のテンプレートコードです。助けてください!

答えて

0

これを試すことができます。

$productField = get_field('ingredients-INCI'); 

すべてのリピータファイルは、この「$ productField」に記載されています。

foreach($productField as $product){ 
    echo $product['ingredients-INCI-group']; 
} 
+0

私はこれを試しましたが、何も通過しません。 – Ashley

+0

コンテンツをループで表示する必要があります。この変数の "$ productField"では、このフィールドの "ingredients-INCI"のすべての値を取得します。私は自分の答えを更新しました – Dinesh

+0

私はあなたの提案を試みたが、多くの運を持っていない。私は最初の投稿で、「原料-INCI-グループ」が「原料」というカスタム分類法から引き抜かれたということを追加しておくべきでした。そのサブフィールドを標準的なテキストフィールドに変換すると、それはコンテンツを取得しますが、それをカスタム分類法から引っ張って戻すと、コンテンツは取得できません。 – Ashley

関連する問題