2

I have this query -

<?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 }?>

I need to show an image called from an advanced custom field called 'advert' which is set to use the image array option where I'm calling the post title.

How can I do this? Thanks.

1 Answer 1

2

Read the get_field doc

In your loop, use $img = get_field("advert", $advert->ID), return an array. Then to get the url, use $img["url"]

The doc

Sign up to request clarification or add additional context in comments.

3 Comments

I've updated my question with my new code, please could you have a look and see if you can see where I'm going wrong?
Change $advert->id ot $advert->ID, it will be better i hope
What if you want to get the acf image (array) and display it in an admin table column? I am setting a variable with get_queried_object_id() and echoing with echo wp_get_attachment_image($image, $size); but it doesnt output anything...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.