0
votes

so after a lot of researching and trials and errors, I come to you. This seems to be very basic and still no luck. The issue is that my image does not appear and in the console it gives me an <img src (unknown) />.

So, in my ACF, I have a field called first_row that contains sub fields, one of the is called left_side_bg. It's attributes are all standard, and is set to return an Image Array. As a side note, I have another subfield called left_side_text.

On my php file, I'm trying to retrieve it like this:

<?php 
    $info = get_field('first_row');
    $left_side_bg = get_sub_field('left_side_bg');
?>

<div class="single-banner">
  <img src="<?php echo $left_side_bg['url']?>" alt="">
     <div class="inner-text">
        <h4><?php echo $info['left_side_text']; ?></h4>
     </div>
</div>

The left_side_text shows fine, but no luck with the image... is there anywhere I can double check or debug this better, or am I fetching the data incorrectly?

As a side note, I have tried different ways to retrieve the image by changing to Image URL, Image ID (in the ACF custom editor) and so on, but no luck, so I returned to the original format I tried to get the image the first time with all the ACF fields as default (getting the Image as an Array).

1

1 Answers

1
votes

get_sub_field() is meant for Repeaters and Flexible Content (rows). I assume left_side_bg and left_side_text are in the same group. Therefore, try it like so:

<?php 
    $info = get_field('first_row');
?>

<div class="single-banner">
  <img src="<?php echo $info['left_side_bg']['url']?>" alt="">
     <div class="inner-text">

It also makes a difference to what your Return Value is configured. I hope it is set to "Image Array". Otherwise, you might have to omit the ['url'] if it's "Image URL" instead.

If that isn't working, it might be a good idea to post a screenshot of what your ACF field configuration (field group) looks like.