Troubleshooting Common Custom Post Type UI Errors and Warnings
Content
Custom Post Type UI (CPTUI) is a powerful tool for managing custom content in WordPress. However, users sometimes encounter PHP warnings, errors, or unexpected behavior. Based on common community reports, this guide explains the most frequent issues and how to resolve them.
Common Error: Invalid Argument Supplied for foreach()
This is one of the most prevalent warnings. It often appears as:
Warning: Invalid argument supplied for foreach() in .../wp-content/plugins/custom-post-type-ui/custom-post-type-ui.php on line 385
Why It Happens:
This warning typically occurs when the data structure for a post type or taxonomy saved by CPTUI becomes corrupted or is missing expected array data. For instance, a post type might be missing its 'labels' array, or the main post type data might not be an array when the plugin expects it to be.
How to Fix It:
- Re-save Your Post Types and Taxonomies: The most common fix is to navigate to CPT UI > Add/Edit Post Types and CPT UI > Add/Edit Taxonomies. Open each of your saved items, and simply click 'Save' without making any changes. This action can rebuild the proper data structure and clear the warning.
- Check for Corrupted Imports: If the issue started after importing settings from another site or a different plugin (like WCK), the imported data might be corrupted. You may need to manually remove the problematic entries from the database. CPTUI stores its settings in the
wp_optionstable under the option namescptui_post_typesandcptui_taxonomies. Warning: Only edit the database if you are comfortable and have a full backup.
Common Error: array_key_exists() Expects Parameter 2 to Be Array
This error, often seen in lines 878 or 1892 of CPTUI files, indicates the code is trying to check for a key in a variable that is not an array.
Why It Happens:
Similar to the foreach error, this suggests the underlying data for a post type is not formatted correctly. It could be a string instead of an array, which often happens if settings are corrupted.
How to Fix It:
- Re-save Settings: As with the first error, try re-saving your post types and taxonomies in the CPTUI admin screens.
- Update the Plugin: In one instance (Thread 21), the 'Custom Post Type UI' team fixed a specific version of this bug in v1.11.1. Always ensure you are running the latest version of the plugin.
Common Issue: Integration with Advanced Custom Fields (ACF)
Many threads report issues where ACF fields don't show data, don't display correctly (e.g., missing WYSIWYG toolbar), or seem to be out of sync.
Why It Happens:
CPTUI and ACF are separate plugins. CPTUI handles the registration of the post type, while ACF handles attaching and displaying custom fields. These issues are rarely caused by CPTUI itself but often by:
- Javascript conflicts from other plugins or the theme.
- The 'Disable the visual editor' setting being checked in the user's profile.
- The load order of plugins. If ACF loads after CPTUI, it might not associate fields correctly in some complex setups.
- Custom code in the theme's
functions.phpfile that interferes with ACF (as was the solution in Thread 10).
How to Fix It:
- Basic Troubleshooting: First, check your user profile to ensure the visual editor is enabled. Then, follow standard conflict testing procedures: switch to a default WordPress theme (like Twenty Twenty-One) and disable all other plugins except CPTUI and ACF. If the problem goes away, re-enable themes and plugins one by one to find the conflict.
- Adjust Load Order (Advanced): If you suspect a load order issue, you can try forcing CPTUI to register its post types later, after ACF has likely loaded. You can add this code to your theme's
functions.phpfile:
remove_action( 'init', 'cptui_create_custom_post_types', 10 );
add_action( 'init', 'cptui_create_custom_post_types', 11 ); - Contact ACF Support: Since the issue usually lies outside of CPTUI's functionality, the ACF support team is often best equipped to help diagnose field-specific problems.
When an Error is Probably Not From CPTUI
It's important to read error messages carefully. Errors that mention files from other plugins, like js_composer_salient (Visual Composer) or post-my-cf7-form, are not caused by CPTUI. For these, you should deactivate CPTUI to confirm, and then seek support from the plugin mentioned in the error message's file path.
Conclusion
Most common CPTUI errors relate to data corruption and can be fixed by re-saving settings. For integration issues with other plugins like ACF, systematic conflict testing is key. Remember, the 'Custom Post Type UI' plugin is solely responsible for registering post types and taxonomies; it does not control how other plugins like ACF or page builders display content on the front end.
Related Support Threads Support
-
Error during import (Uncaught TypeError: in_array(): )https://wordpress.org/support/topic/error-during-import-uncaught-typeerror-in_array-2/
-
Import of Custom Post Type not workinghttps://wordpress.org/support/topic/import-of-custom-post-type-not-working/
-
Plugin breaking ALL frontend search querieshttps://wordpress.org/support/topic/plugin-breaking-all-frontend-search-queries/
-
json errorhttps://wordpress.org/support/topic/json-error-40/
-
ACF not working Fields anymore on the front endhttps://wordpress.org/support/topic/acf-not-working-fields-anymore-on-the-front-end/
-
Uncaught TypeError in the file /wp-admin/includes/post.php on line 1712https://wordpress.org/support/topic/uncaught-typeerror-in-the-file-wp-admin-includes-post-php-on-line-1712/
-
Cannot read properties of undefined (reading ‘toLocaleLowerCase’)https://wordpress.org/support/topic/cannot-read-properties-of-undefined-reading-tolocalelowercase/
-
Crash after importing jsonhttps://wordpress.org/support/topic/crash-after-importing-json/
-
ACF pro CPT and Taxonomies to CPT UIhttps://wordpress.org/support/topic/acf-pro-cpt-and-taxonomies-to-cpt-ui/
-
warning Invalid argument supplied for foreach() custom-post-type-ui/custom-post-https://wordpress.org/support/topic/warning-invalid-argument-supplied-for-foreach-custom-post-type-ui-custom-post/
-
Warning error in v1.11.0https://wordpress.org/support/topic/warning-error-in-v1-11-0/
-
ACF field still visible in custom type page ad even if I have removed ithttps://wordpress.org/support/topic/acf-field-still-visible-in-custom-type-page-ad-even-if-i-have-removed-it/
-
Fatal error: Uncaught TypeError: array_key_exists(): /inc/utility.php:878https://wordpress.org/support/topic/fatal-error-uncaught-typeerror-array_key_exists-inc-utility-php878/
-
CPTUI Causes critical error messages: PHP Warning: Invalid argument suppliedhttps://wordpress.org/support/topic/cptui-causes-critical-error-messages-php-warning-invalid-argument-supplied/
-
Function register_rest_route was called incorrectly.https://wordpress.org/support/topic/function-register_rest_route-was-called-incorrectly-7/
-
Warnings in headers in front and backendhttps://wordpress.org/support/topic/warnings-in-headers-in-front-and-backend/
-
ACF field values not showinghttps://wordpress.org/support/topic/acf-field-values-not-showing/
-
Error array_key_exists() expects parameter 2 to be arrayhttps://wordpress.org/support/topic/error-array_key_exists-expects-parameter-2-to-be-array-2/
-
Errorhttps://wordpress.org/support/topic/error-1514/
-
ACF Being used with CPT not showing Wysiwyghttps://wordpress.org/support/topic/acf-being-used-with-cpt-not-showing-wysiwyg/
-
Array warning for cptui_post_thumbnail_theme_support php 8.3.14https://wordpress.org/support/topic/array-warning-for-cptui_post_thumbnail_theme_support-php-8-3-14/
-
Several errors after export/import taxonomieshttps://wordpress.org/support/topic/several-errors-after-export-import-taxonomies/
-
Pulling ACF from CPT UIhttps://wordpress.org/support/topic/pulling-acf-from-cpt-ui/
-
Post types disappearedhttps://wordpress.org/support/topic/post-types-disappeared/
-
I get error invalid argumenthttps://wordpress.org/support/topic/i-get-error-invalid-argument/
-
Custom Data from ACF isn’t showing uphttps://wordpress.org/support/topic/custom-data-from-acf-isnt-showing-up/
-
Warning When I create post on my custom Post typehttps://wordpress.org/support/topic/warning-when-i-create-post-on-my-custom-post-type/