skip to Main Content

The array is working fine on local machine and loops through the images but it fails to work on the aws server. It says "Trying to access array offset on value of type null".

<?php              
                   $image1 = get_field('add_image');  
                   $image2 = get_field('add_image2');  
                   $image3 = get_field('add_image3');  
                   $images = array($image1, $image2, $image3);  
                   
     
 ?>
<?php $count = 0;  ?>
<?php foreach($images as $value):  ?> 
     <img src="<?php echo esc_url($value['url']); ?>" class="d-block w-100 wrap-image-single responsive " alt="..."> </a>
<?php $count++; endforeach;  ?> 

2

Answers


  1. You may wish to try some basic debug…

    1. Check that image1,2,3 all have values e.g. var_dump($image1)
    2. Try and dump the $images array and see what you have. Do you in fact have the ‘url’ key on each sub-array?
    Login or Signup to reply.
  2. This might be a minor issue. Here is my process of debugging the issue:

    1. Please check that you are using valid names like add_image2, add_images3 for the function get_field
    2. Another silly mistake might be that you would be making changes in one file and seeing the results on another file.
    3. Also, make sure that you have the updated code on AWS.

    These are my two cents. Let me know how it goes .. 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search