[英]show ACF field value from custom post type category
我正在嘗試顯示一個已添加到自定義帖子類型類別(分類法)的字段。 該分類法稱為“類別產品”。 我已經添加了一個名為“ category_image”的字段,我想在其中添加圖像。 但是acf字段未顯示該值。 到目前為止,這是我嘗試過的。
<?php
$taxonomy = 'category-products';
$terms = get_terms($taxonomy);
if ( $terms && !is_wp_error( $terms ) ) :
?>
<ul>
<?php foreach ( $terms as $term ) { ?>
<li class="cate col-md-2">
<a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?>
<?php the_field('category_image', $terms ); ?>
</a></li>
<?php } ?>
</ul>
<?php endif;?>
如果您在此處閱讀文檔: https : the_field()
,則應將Post ID作為the_field()
函數的第二個參數傳遞。 例如。
the_field($selector, [$post_id], [$format_value]);
注意post_id
和$format_value
參數都是可選的。
但是,對於術語,我認為您需要將術語名稱和術語ID作為第二個參數傳遞。
the_field( 'category_image', $term->name . '_' . $term->term_id );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.