如何显示图像阵列中的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"的高级自定义字段调用的图像,该字段设置为使用我调用帖子标题的图像数组选项。

我该怎么做?谢谢

读取get_field文档

在循环中,使用$img = get_field("advert", $advert->ID),返回一个数组。然后使用$img["url"] 获取url

文档