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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码