【问题标题】:Advanced Custom Fields Repeater inside product category (woocommerce)产品类别内的高级自定义字段中继器(woocommerce)
【发布时间】:2014-12-05 20:13:55
【问题描述】:

我目前正在使用 ACF 5。我已在产品类别上设置了转发器。

我目前正在努力解决如何让它输出信息。我在 acrhive-product 循环中,我正在更新以下包含输出内容的模板:

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

    <?php wc_get_template_part( 'content', 'product_cat' ); ?>

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

在 content-product_cat.php 中,中继器的每个循环都有以下内容。所有基本信息已经显示,标题,woocommerce 类别图像等。它是我添加到类别本身的中继器,我无法显示。

<?php
    $terms = get_field('attributes', 'product_cat_'.$term->term_id); 
    if($terms): ?>
        <ul>
    <?php foreach( $terms as $term ): ?>
            <li>
             <?php the_sub_field('attribute'); ?>
            </li>
    <?php endforeach; ?>
        </ul>
      <?php endif; ?>

任何想法将不胜感激

【问题讨论】:

  • 您是否启用了WP_DEBUG?你可能想要。至少,如果您有未定义的对象/变量,这可能会告诉您。你如何定义$term-&gt;term_id?我会从那里开始,因为没有term,你甚至永远不会进入foreach() 循环。之后,我对 ACF 的了解就不够了。

标签: php wordpress woocommerce advanced-custom-fields


【解决方案1】:

先打印出参数:

<?php print_r($category);?>

然后使用其输出生成以下内容:

<?php 
        $cat_id = $category->term_id; //used below to get a the acf from the categories!
    ?>


<?php
        // $cat_id = $category->term_id;

        $terms_features = get_field('features', 'product_cat_'.$cat_id); 
        if($terms_features): 
            // print_r($terms_features); 
        ?>
        <ul>
        <?php foreach( $terms_features as $terms_feature ): 
        // print_r($term); 
        ?>
        <?php
          $image_icon = $terms_feature['icon'];
          $image_icon_show = $image_icon[sizes][large];
          // print_r($image_feature);
        ?>
                <li>
                    <img src="<?php echo $image_icon_show;?>" />
                    <?php echo $terms_feature['description'];?>
                </li>
         <?php endforeach; ?>
        </ul>
      <?php endif; ?>

【讨论】:

    猜你喜欢
    • 2015-12-30
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 2016-09-12
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    相关资源
    最近更新 更多