get_the_ID() is working on my local development but not on staging server

Great to see a StackExchange for WP! Ok so I’m working on pulling images and dates from piklist custom post types and I got this working on my local, BUT when I move it to WPEngine I get a white page until I take the code out. The date code doesn’t throw a blank page but won’t pull the dates entered. Can anyone tell me what about this code may be causing this? Thanks in advance!

CODE

single.php

<?php while ( have_posts() ) : the_post(); ?>

  <?php

    $image_ids = get_post_meta(get_the_ID(), 'my_media', false);

    foreach ($image_ids as $image)
    {

      echo '<img src="https://wordpress.stackexchange.com/questions/158341/" . wp_get_attachment_image_src($image, 'large')[0]  . "https://wordpress.stackexchange.com/questions/158341/"/>';

    }
  ?>

  <?php echo get_post_meta(get_the_ID(), 'my_date', true); ?>

  <?php get_template_part( 'content', themeblvd_get_part( 'single' ) ); ?>

  <?php themeblvd_single_footer(); ?>

  <?php if ( themeblvd_supports( 'comments', 'posts' ) ) : ?>
    <?php comments_template( '', true ); ?>
  <?php endif; ?>

<?php endwhile; ?>

1 Answer
1

The problem is this part:

wp_get_attachment_image_src($image, 'large')[0]

In old PHP versions like 5.3 and below, you cannot reference an entry ([0]) from the returned array of a function. The problem is that WP Engine is still on PHP 5.3, which reached end of life recently and doesn’t get security updates anymore. For the history see PHP 5.3 – Thanks for all the Fish.

You have two options:

  1. Find all occurrences of modern syntax and rewrite them to make it compatible with 5.3. In this case:

    $img_data = wp_get_attachment_image_src($image, 'large');
    $src = $img_data[0];
    
  2. Switch to a newer PHP version, preferably 5.5. If your current hoster cannot do that find a better one.

Leave a Comment