显示 WooCommerce 自定义分类 ACF 字段

我为 woocommerce 产品“coffee_type”创建了自定义分类法。 我为此分类创建了一个 ACF 图像字段“coffee_type_image”。

我想在产品页面上显示带有链接的图像,而不是分类法的名称。 我在这里阅读了大多数关于在分类法上显示 acf 图像的文章,但每一篇都是关于使用存档分类法页面而不是产品页面。 我正在编辑 single-product.php(确切地说是 content-single-prodct.php)。

这是我当前的循环

<?php $wcatTerms = get_terms('coffee_type',array('hide_empty' => 0,'parent' => 0));
foreach ($wcatTerms as $wcatTerm):
?>
<ul>
   <li>
      <a href="<?php echo get_term_link($wcatTerm->slug,$wcatTerm->taxonomy); ?>"><?php echo $wcatTerm->name; ?></a>
        <?php $taxonomy = $queried_object->taxonomy;?>
   </li>
</ul>
<?php
endforeach;
?>

这是#wcatTerm 的 var_dump

object(WP_Term)[3704]
  public 'term_id' => int 33
  public 'name' => string 'coffee and chicory' (length=18)
  public 'slug' => string 'coffee-and-chicory' (length=18)
  public 'term_group' => int 0
  public 'term_taxonomy_id' => int 33
  public 'taxonomy' => string 'coffee_type' (length=11)
  public 'description' => string '' (length=0)
  public 'parent' => int 0
  public 'count' => int 2
  public 'filter' => string 'raw' (length=3)

这是get_queried_object()的var_dump;

object(WP_Post)[3316]
  public 'ID' => int 671
  public 'post_author' => string '1' (length=1)
  public 'post_date' => string '2021-07-27 14:04:09' (length=19)
  public 'post_date_gmt' => string '2021-07-27 14:04:09' (length=19)
  public 'post_content' => string '<!--(figmeta)eyJmaWxlS2V5IjoiOWxOQjFWT01TaWFzVmx6cmxTUTl3YiIsInBhc3RlSUQiOjE2MjEzNjQ4LCJkYXRhVHlwZSI6InNjZW5lIn0K(/figmeta)--><!--(figma)ZmlnLWtpd2kEAAAARCMAALV7f5wsS1VfVc/M/rh7730/eTyeiIiIiKjvF+89EJGenp7dvjsz3a+7Z/beJzL0zvTuzruzM8P0zN67T0REQgxBRFQgiAQJUUSjqPgrQUVi1CSKvxERFRGnmYlJzC9jjMn3W9W/5u59fvzH+/ncqVOnTp06deqcU6eqet8m23GSRIdxeDqLhbjlkut0+kFo+qHAv47bsPvWjtnZtgNUZTew/VLdUNR2pwG4EjjbhbmFqBqEV1o2gJoC+oFNXmuKVnHuB7uO1/ftlmuy53rHDZ3mlX6w43ZbjX7X2/bNBvtvpGC/4XZY38zqvt307WAHqHOBZXfsPtDeTv/Rru1fAXKrjPRtr0Xk+Yb'... (length=52896)
  public 'post_title' => string 'Product Name 1' (length=14)
  public 'post_excerpt' => string '<!--(figmeta)eyJmaWxlS2V5IjoiOWxOQjFWT01TaWFzVmx6cmxTUTl3YiIsInBhc3RlSUQiOjE2MjEzNjQ4LCJkYXRhVHlwZSI6InNjZW5lIn0K(/figmeta)--><!--(figma)ZmlnLWtpd2kEAAAARCMAALV7f5wsS1VfVc/M/rh7730/eTyeiIiIiKjvF+89EJGenp7dvjsz3a+7Z/beJzL0zvTuzruzM8P0zN67T0REQgxBRFQgiAQJUUSjqPgrQUVi1CSKvxERFRGnmYlJzC9jjMn3W9W/5u59fvzH+/ncqVOnTp06deqcU6eqet8m23GSRIdxeDqLhbjlkut0+kFo+qHAv47bsPvWjtnZtgNUZTew/VLdUNR2pwG4EjjbhbmFqBqEV1o2gJoC+oFNXmuKVnHuB7uO1/ftlmuy53rHDZ3mlX6w43ZbjX7X2/bNBvtvpGC/4XZY38zqvt307WAHqHOBZXfsPtDeTv/Rru1fAXKrjPRtr0Xk+Yb'... (length=22771)
  public 'post_status' => string 'publish' (length=7)
  public 'comment_status' => string 'open' (length=4)
  public 'ping_status' => string 'closed' (length=6)
  public 'post_password' => string '' (length=0)
  public 'post_name' => string 'product-name-1' (length=14)
  public 'to_ping' => string '' (length=0)
  public 'pinged' => string '' (length=0)
  public 'post_modified' => string '2021-07-31 11:57:41' (length=19)
  public 'post_modified_gmt' => string '2021-07-31 11:57:41' (length=19)
  public 'post_content_filtered' => string '' (length=0)
  public 'post_parent' => int 0
  public 'guid' => string 'http://localhost/orc/?post_type=product&p=671' (length=50)
  public 'menu_order' => int 0
  public 'post_type' => string 'product' (length=7)
  public 'post_mime_type' => string '' (length=0)
  public 'comment_count' => string '3' (length=1)
  public 'filter' => string 'raw' (length=3)

如何在 ACF 字段“coffee_type_image”中显示带有存档页面链接的内容?我不知道如何将 ACF 传递给此分类法以使用 get_field();

我尝试过类似的事情

<?php $term = get_field('coffee_type_image',$wcatTerm->term_id);?>

<?php $term = get_field('coffee_type_image',$wcatTerm->term_id,$wcatTerm->taxonomy);?>

但是他们总是返回null 谢谢

sttea 回答:显示 WooCommerce 自定义分类 ACF 字段

我刚刚找到了我的问题的答案。如果其他人需要这个,我会发布。

<?php $term = get_field('coffee_type_image','coffee_type_' . $wcatTerm->term_id);?>
 <a href="<?php echo get_term_link($wcatTerm->slug,$wcatTerm->taxonomy); ?>"><img src="<?php echo $term; ?>" alt="" class="img-responsive"></a>
本文链接:https://www.f2er.com/5229.html

大家都在问