提问者:小点点

显示自定义职位类型类别中的ACF字段值


我试图显示我添加到自定义帖子类型类别(分类法)中的字段。分类法称为“类别产品”。我已经添加了一个名为“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;?>

共1个答案

匿名用户

如果您阅读此处的文档:https://www.advancedcustomfields.com/resources/the_field/,您应该将Post ID作为函数的第二个参数传递给\u field()。如。

_字段($selector,[$post_id],$format_value])

注意到post_id$format_value参数都是可选的。

然而,对于术语,我认为您需要传递术语名称和术语id作为第二个参数eg。

_字段('category_image',$term-