0
votes

I upgraded to Wordpress 4.6.1 and a calendar page that displayed data from a number of different post types, starting showing an error:

Warning: Invalid argument supplied for foreach() in /home/centkuti/public_html/wp-content/themes/central-square-theater/page-templates/page-calendar.php on line 117

This wasn't happening before the upgrade and I examined the code and it hasn't changed. Here are lines 115 to 120:

<?php
  $prepost = get_post_custom_values('pre_post_related_show', $row->post_id);
  foreach($prepost as $v)
  {
    //echo $v;
  }
?>

Your help is appreciated.

1
Make sure that $prepost is an array, and not null or false, before trying to iterate through it.aynber
It is likely that this issue always existed but the new install no longer suppresses that error level or is configured to show errors where it once suppressed them. Anyways, aynber's comment is correct.MonkeyZeus
What do you expect from a foreach with a commented-out body?zx485

1 Answers

1
votes

This should work

<?php
$prepost = get_post_custom_values('pre_post_related_show', $row->post_id);
if(is_array($prepost) && count($prepost)>0) {
  foreach($prepost as $v) {
    //echo $v;
  }
}
?>