简体   繁体   中英

How to add ACF field after WooCommerce archive page title

I am trying to print an ACF field after the WooCommerce archive page title.

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM