[英]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.