dpps0715 2016-08-25 10:41
浏览 44

ACF中继器字段显示

I have created a custom post type called 'products' and a custom taxonomy within the post type called 'Ingredients'.

I've added a repeater field called 'ingredients-INCI' and sub field of 'ingredients-INCI-group' which calls the values from the taxonomy 'Ingredients'.

Custom Repeater Field Screenshot:

Click to view Custom Repeater Field Screenshot

Each product has many ingredients, I would like to display a list of the chosen ingredients for the product. Here's my template code:

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

get_header(); ?>

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

        <?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">

        <?php

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

    // 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">
        
        RESULTS HERE
        
</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 -->

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

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

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

This code seems to break the output. Please help!

</div>
  • 写回答

1条回答 默认 最新

  • dongxie548548 2016-08-25 11:22
    关注

    You can try this.

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

    All the repeater fileds will be listed in this "$productField" valriable.

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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据