Fixing the 'array_merge(): Argument #2 is not an array' Error in WP-PageNavi
Content
If you're seeing a warning message like Warning: array_merge(): Argument #2 is not an array in .../wp-pagenavi/scb/Options.php on line 62, you're not alone. This is a common issue reported by users of the WP-PageNavi plugin across various WordPress environments, particularly on PHP 7.2 and newer versions, and on multisite installations.
Why This Error Occurs
The error originates in the scb/Options.php file, which is part of the framework WP-PageNavi uses. The core of the problem is that the get_option() function is expected to return an array to be merged with the plugin's default settings. However, in some cases, this function returns something other than an array—sometimes a string, or in rare cases, a boolean. When this non-array value is passed to array_merge(), PHP throws a warning.
This often happens when the plugin's settings are missing or corrupted in the WordPress database wp_options table. This can occur after a site migration, on a fresh installation where settings weren't properly saved, or within a WordPress multisite network where options might not be propagated correctly to sub-sites.
How to Fix It
Here are the most effective solutions, starting with the simplest and most common fix.
Solution 1: Resave Your Plugin Settings (Most Common Fix)
The easiest and most recommended first step is to simply resave the plugin's configuration. This action rewrites the settings to the database, ensuring they are stored correctly as an array.
- Navigate to Settings → PageNavi in your WordPress admin dashboard.
- Review the settings. You don't need to change anything, but you can if you wish.
- Click the 'Save Changes' button.
This forces the plugin to save a proper array of options, which should immediately resolve the warning. This solution has been confirmed to work by the plugin's author in support threads.
Solution 2: Apply a Code Patch
If the first solution does not work, or if the error persists on a multisite network, the underlying issue can be fixed by modifying the plugin's code. The community has consistently identified a specific code change that resolves the problem by explicitly casting the value from the database to an array.
Warning: Editing plugin files is a temporary solution, as your changes will be overwritten the next time the plugin is updated. Always create a backup of your site before proceeding.
- Access your website's files via FTP, SFTP, or your hosting provider's file manager.
- Navigate to the plugin directory:
/wp-content/plugins/wp-pagenavi/ - Open the file
scb/Options.phpin a code editor. - Find the problematic line (common line numbers are 44, 46, or 62). It will look similar to this:
$data = array_merge( $this->defaults, get_option( $this->key, array() ) ); - Modify this line by adding
(array)to cast the return value to an array:$data = array_merge( $this->defaults, (array) get_option( $this->key, array() ) ); - Save the file and upload it back to your server, overwriting the old one.
This modification ensures that even if get_option() returns a non-array, it will be converted into one before the merge, preventing the PHP warning.
Conclusion
The 'Argument #2 is not an array' error in WP-PageNavi is almost always related to a database issue where the plugin's settings are not stored as expected. The first and safest step is to always try resaving the settings in the WordPress admin. If that fails, the code patch provides a reliable, community-vetted workaround. For users on multisite networks, ensuring that settings are saved for the individual sub-site (not just the network admin) is crucial.
Related Support Threads Support
-
Argument #2 is not an array in … scb/Options.php on line 62https://wordpress.org/support/topic/argument-2-is-not-an-array-in-scboptionsphp-on-line-62/
-
Warning: array_merge(): Argument #2 is not an array in /wp-content/plugins/wp-pahttps://wordpress.org/support/topic/warning-array_merge-argument-2-is-not-an-array-in-wp-contentpluginswp-pa/
-
Warning compatibility PHP 8.0https://wordpress.org/support/topic/warning-compatibility-php-8-0-3/
-
WP_DEBUG notice core.php on line 17https://wordpress.org/support/topic/wp_debug-notice-corephp-on-line-17/
-
[Plugin: WP-PageNavi] Warning: array_merge() [function.array-merge]: Argument #2…errorhttps://wordpress.org/support/topic/plugin-wp-pagenavi-warning-array_merge-functionarray-merge-argument-2error/
-
array_merge() [function.array-merge]: Argument #2…errorhttps://wordpress.org/support/topic/array_merge-functionarray-merge-argument-2error/
-
PHP Errorhttps://wordpress.org/support/topic/php-error-345/
-
Fatal PHP error on 2.93https://wordpress.org/support/topic/fatal-php-error-on-2-93/
-
array errorhttps://wordpress.org/support/topic/array-error-2/
-
Issue in paginationhttps://wordpress.org/support/topic/issue-in-pagination/
-
PHP 7.2 warninghttps://wordpress.org/support/topic/php-7-2-warning-7/
-
Errohttps://wordpress.org/support/topic/erro-2-2/
-
Warning: array_merge() issuehttps://wordpress.org/support/topic/warning-array_merge-issue/