如何显示图像数组中的 acf 图像

How to display acf image from image array

我有这个问题 -

<?php if (has_term( 'channel', 'listing_area' )) { ?>


<?php
        $posts = get_posts(array(
'numberposts'   => 3,
'post_type'     => 'adverts',
'order_by' => 'title',
'order' => 'random',
'meta_query'    => array(
    'relation'      => 'AND',
    array(
        'key'       => 'associate_adverts',
        'value'     => '1822',
        'compare'   => 'LIKE',
    )
),
 ));

    ?>


  <?php //if it's returning the object

     foreach($posts as $advert){

       $img = get_field("advert", $advert->id);?>

 <img src="<?php echo $img["url"]; ?>"/>

  <?php }?>

我需要显示从名为 'advert' 的高级自定义字段调用的图像,该字段设置为使用我调用 post 标题的图像数组选项。

我该怎么做?谢谢

阅读 get_field 文档

在您的循环中,使用 $img = get_field("advert", $advert->ID)、return 数组。 然后要获得 url,请使用 $img["url"]

The doc