infoWordPress CorecodePHPwebwordpresserrorerrorextensionpluginlabelCommonwarningModerate

Invalid argument supplied for foreach()

The warning appears when PHP receives a variable that is not iterable in a foreach loop. WordPress core functions, plugins, themes, or custom code often pass null, a string, or an undefined variable where an array or object is expected. This situation triggers the PHP runtime to emit the Invalid argument supplied for foreach() notice.

Typical triggers include uninitialized global objects such as $wp_styles->queue, outdated core files that assume a property is always an array, plugins that deregister core objects, and options stored in the database that return null instead of an array. When the loop runs without a valid iterable, PHP stops normal output and might cause additional header errors.

Symptoms

[dashicons-warning]
PHP warning displayed
A warning appears in the front‑end or admin screen showing the exact message.
[dashicons-admin-appearance]
Blank page sections
Parts of the page, such as styles or scripts, fail to load.
[dashicons-admin-site]
Headers already sent errors
Subsequent header errors appear after the warning due to early output.

Common Causes

Non‑iterable variable
Variable is null, a scalar, or undefined when foreach expects an array or object.
Uninitialized WordPress globals
Globals like $wp_styles->queue or $active_plugins are not set before use.
Plugin or theme conflict
A plugin or theme overwrites a core object, leaving its property empty.
Out‑of‑date core or theme
Older code assumes a property is always an array, causing null values.
Corrupt option in database
An option that should be an array returns null due to corruption.
Need this fixed right now?

Don't waste your day debugging. Our experts can Fix your issues in under 2 hours.*

Success Rate

100% Guaranteed

Starting from

$35 /hour
99+

Trusted by Business Owners

“I spent 3 days trying to fix the Elementor loading loop. These guys fixed it in 20 minutes. Lifesavers!”

— Sarah J., Web Designer

Related Issues

contact_mail
Contact Form 7: REST API request failed: 503 Service Unavailable
A 503 Service Unavailable response stops Contact Form 7 from sending data...
apiREST APIerror503descriptioncontact-form-7
contact_mail
Contact Form 7: REST API request failed: 429 Too Many Requests

The form tries to send data through the WordPress REST API. The...

apiREST APIerrorerrorsecurityfirewalldescriptioncontact-form-7settingsserver_configuration
contact_mail
Contact Form 7: REST API request failed: 401 Unauthorized

The form tries to send data via the WordPress REST API. The...

apiREST APIadmin_panel_settingspermissionsdescriptioncontact-form-7lock401
contact_mail
Contact Form 7: File upload error: temporary directory missing

The error appears when Contact Form 7 cannot locate a writable temporary...

codePHPcloud_offupload erroradmin_panel_settingspermissionsdescriptiontemporary filedescriptioncontact-form-7
contact_mail
Contact Form 7: Mail (2) sending failed: PHP mail() function disabled

Contact Form 7 reports a failure for Mail (2) when the PHP...

codePHPerrorerrordescriptioncontact-form-7mailMailsettingsserver_configuration
contact_mail
Contact Form 7: Mail (2) sending failed: SSL certificate verification failed

Contact Form 7 reports a failure when trying to send the secondary...

errorerrorlocksslcodecURLdescriptioncontact-form-7