2016-08-25 3 views
0

"제품"이라는 사용자 정의 포스트 유형과 '성분'이라는 포스트 유형 내에서 사용자 정의 분류를 작성했습니다.ACF 리피터 필드 디스플레이

'ingredients-INCI'라는 리피터 필드와 분류법 'Ingredients'의 값을 호출하는 'ingredients-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

관련 문제