简体   繁体   English

WooCommerce存档页面标题后如何添加ACF字段

[英]How to add ACF field after WooCommerce archive page title

I am trying to print an ACF field after the WooCommerce archive page title.我正在尝试在 WooCommerce 存档页面标题之后打印ACF字段。

I use the following code but not working.我使用以下代码但不工作。

woocommerce_page_title();
global $post;
if( get_field('acf_field',$taxonomy . '_' . $termId) ):
    $taxonomy = get_query_var('taxonomy'); 
    $term_id = get_queried_object()->term_id; 
    the_field('acf_field', $taxonomy . '_' . $term_id);
else: 
endif; 

I'm not sure why you used global $post variable here, since you have not provided the entire code but I don't think you need it for outputting the acf field.我不确定你为什么在这里使用global $post变量,因为你没有提供完整的代码,但我认为你不需要它来输出acf字段。

So try the following snippet:因此,请尝试以下代码段:

woocommerce_page_title();

$term_id  = get_queried_object()->term_id;
$taxonomy = get_queried_object()->taxonomy;

$custom_field_value = get_field('you_acf_field_here', $taxonomy . '_' . $term_id);

if ($custom_field_value) :
    echo $custom_field_value;
else :
    echo 'NO CUSTOM FIELD FOUND!';
endif;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 存档页面中的产品标题下方显示 ACF 字段/图像 - Display ACF field/image below the product title in WooCommerce archive pages 用ACF自定义字段替换Woocommerce分类标准存档页面标题 - Replace Woocommerce taxonomy archive pages title with ACF custom field 分页后如何将 ACF 字段挂接到 Woocommerce 类别页面的“after_shop_loop”部分的底部 - How to hook an ACF field into the bottom of the "after_shop_loop" section of a Woocommerce category page after pagination Woocommerce-在存档页面上重新定位标题 - Woocommerce - Reposition Title on Archive Page WooCommerce | 在存档页面上的产品标题下添加产品副标题 - WooCommerce | Add product subheading underneath product title on archive page 如何在存档页面上的 woocommerce 产品标题之前显示 SKU - How to show SKU before woocommerce product title on archive page 在 WooCommerce 内容小部件中的产品标题后显示 ACF 自定义字段 - Display ACF custom field right after the product title in WooCommerce content widget 如何使用ACF将自定义字段添加到woocommerce商店页面 - How to add custom fields to woocommerce shop page with acf 在 WooCommerce 产品归档循环中显示 ACF 字段值 - Display an ACF field values in WooCommerce product archive loop Woocommerce “存档页面”产品标题及链接 - Woocommerce “archive page” product title with link
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM