循环显示分类法acf字段

时间:2018-06-02 12:54:45

标签: wordpress custom-post-type advanced-custom-fields

在高级自定义字段(ACF)中,我创建了一个图像字段,并将其添加到自定义帖子类型的类别中,以便每个类别都可以拥有自己的图像。然后我创建了一个循环,显示该自定义帖子类型的类别。这样可行,但我无法获取我在ACF字段中上传的图像以供显示。

显示自定义帖子类型类别的代码:

<?php $taxonomy = 'customposttype'; $terms = get_terms($taxonomy); if ( $terms && !is_wp_error( $terms ) ) : ?>
<?php foreach ( $terms as $term ) { ?>      

    <?php echo $term->name; ?>
    // display acf image

<?php } ?>  
<?php endif;?>

我尝试使用&#39; array_combine&#39;但我无法让它发挥作用。

1 个答案:

答案 0 :(得分:1)

在循环中尝试此代码

$term_image = get_term_meta( $term->term_id , 'category_afbeelding', true);

$image_attributes = wp_get_attachment_image_src( $term_image,’full’);
 if ( $image_attributes ) : 
  <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" />
endif;
相关问题