douxi6903 2019-01-24 15:24
浏览 37
已采纳

WooCommerce:ACF价值不是通过产品类别

I created custom fields for a WooCommerce category. Location shown below & they work correctly.

Woocommerce category ACF fields

However, when I go to my archive.php file and attempt a the_field('category_banner), it retrieves no data. Here is an example of how I've laid it out.

<?php
$categorybanner      = get_field('category_banner');
$categorydescription = get_field('category_description');
?>

<div class="container-fluid" id="ivy-banner" style="background: url('<?php echo $categorybanner ?>') center / cover"></div>
<h4 class="text-black"><?php echo $categorydescription; ?></h4>

Any reason why this code doesn't work? I can only assume it has got something to do with the location rather than the code itself. How can I circumvent this?

  • 写回答

1条回答 默认 最新

  • doujiu5464 2019-01-24 15:50
    关注

    Please try the below Code. It may help you to get the values.

        <?php
      $term = get_queried_object();
      $categorybanner      = get_field('category_banner', $term);
      $categorydescription = get_field('category_description', $term);
    ?>
    
    <div class="container-fluid" id="ivy-banner" style="background: url('<?php echo $categorybanner ?>') center / cover"></div>
    <h4 class="text-black"><?php echo $categorydescription; ?></h4>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看