Error: Warning: Invalid argument supplied for foreach() in /home/gazettev/public_html/wp-content/themes/exquisite-wp/template-home.php on line 118

Code File: http://ideone.com/VNLGKq

Note: Im not a Programmer. Please Change the code. Wordpress version 4.0.1

  • 2
    Please add your code directly to your question – Pieter Goosen Dec 19 '14 at 9:38
  • code is too long – Nash Patel Dec 19 '14 at 9:43
  • 2
    You should only post relevant code. Remove all irrelevant firts – Pieter Goosen Dec 19 '14 at 10:27

It looks like your $categories is an empty array. To solve this always check if the array is empty or not.

In line 117 add code to check if array is empty

<?php if( !empty( $categories ) ){ ?>

and in line number 167 replace

<?php } ?>


<?php } } ?>

If you want to permanently remove any error or warning message you can use the php code error_reporting(0);. Pase this in top of your functions.php file.

Additionally open wp-config.php file and check for WP_DEBUG. It must be false;

define( 'WP_DEBUG', false );
| improve this answer | |
  • Don't replace curlies with : and endif. It makes code hard to read and to debug. Most code editors don't support this syntax, but all support curlies – Pieter Goosen Dec 19 '14 at 10:26
  • I think it's better now. I edited the answer. – Karun Dec 19 '14 at 10:27
  • Much better. Look, your original syntax is 100% valid, nothing wrong with it, it is just a pain when it comes to debugging code and reading it. It still is personal preference, but always good to know alternatives to what you are doing :-) – Pieter Goosen Dec 19 '14 at 10:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.