I'm having a serious issue with Wordpress 3.1 with Multi Site enabled and my themes custom shortcode generator. For some reason, I'm getting the following error whenever I create a new page/post/custom post type page, etc. It is specifically an issue with radio buttons and the 'name' tag. When its removed, everything works fine. When it is set to a variable, I get the error. However, setting the variable to a constant (such as text) causes it to work again.

This is the error I am getting; I have no clue what it means and what is causing it:

Warning: Invalid argument supplied for foreach() in /home/matthew/public_html/wp-admin/includes/post.php on line 197

Warning: Cannot modify header information - headers already sent by (output started at /home/matthew/public_html/wp-admin/includes/post.php:197) in /home/matthew/public_html/wp-includes/pluggable.php on line 897

Here is the PHP code (check line 892): http://pastebin.com/BNK7wE2W

I'm a bit skeptical about releasing too much information before the theme is released, but if access to the admin panel is required then if possible get in touch with me.

Thanks in advance, Matthew.


I did spot one problem in your case clause for radio buttons: In your <label> tag, you use $val, but I think you meant $option['id'].

I don't see how it could be related to the foreach error you're getting, but it won't hurt to fix it.

The odd thing is that the real error is coming from core code: wp-admin/includes/post.php, line 197. It looks like you're passing in some post meta, but you aren't passing in an array, like it wants. Does that help you narrow things down?

| improve this answer | |
  • Not really. The error stops happening when I remove the Shortcode Generator meta box, so I'm pretty sure its that. The Shortcode Generator doesn't have a Post Save function, so it shouldn't be passing anything when the post is published. When you remove that line (892), the error also stops happening. The radio button case doesn't seem to like <code>$option['id']</code> and I don't know why. Setting it to rand(0, 100) through up a completely different error. – Matthew Ruddy Feb 28 '11 at 22:24
  • I messed around with the code a bit. Removing the 'if($option['std'] == $opt) { echo 'checked="checked"'; }' has also fixed the error. It seems as though Wordpress is getting all the checked radio buttons as part of an array or something similar.. Or maybe not; just a guess. – Matthew Ruddy Feb 28 '11 at 22:38
  • You're saying that if you comment out line 892 (where you output the <input> tag for a radio button), the error goes away? – Dougal Campbell Feb 28 '11 at 22:43
  • Yes. I've managed to narrow it down even further though; removing the 'if($option['std'] == $opt) { echo 'checked="checked"'; }' fixes the error. Cannot figure out why this would be.. – Matthew Ruddy Feb 28 '11 at 23:06
  • The pastebin code has expired... – Dougal Campbell Mar 1 '11 at 20:19

When you get:

Warning: Cannot modify header information - headers already sent by (output started at...

Reason and Solution : It is usually because there are spaces, newlines, or other garbage before an opening <?php tag or after a closing ?> tag. make sure there are none and save as utf-8 without bom

| improve this answer | |
  • Not this time. The spurious output is coming from the PHP Warning message generated in wp-admin/includes/post.php as I described in my answer. – Dougal Campbell Feb 28 '11 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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