PHP7升级致WordPress Taxonomy Order插件失效,求解决方案
Hey there, let's get that PHP warning sorted out. The issue here is that PHP 7.2 and later enforces stricter rules for the count() function — it only accepts arrays or objects that implement the Countable interface. The old Taxonomy Order plugin's code on line 280 is passing a non-countable value (like null or a scalar) into count(), which triggers the warning.
Here's how to fix it step by step:
First, locate the
taxonomy-order.phpfile in your plugins directory, then jump to line 280. You'll likely see a line that looks something like this:$term_count = count($some_variable);(The variable name might be different, like
$termsor$items— focus on thecount()call here.)Replace that line with a conditional check to ensure we only call
count()on countable values. If your server runs PHP 7.3 or newer, use theis_countable()function for cleaner code:$term_count = is_countable($some_variable) ? count($some_variable) : 0;If you're stuck on an older PHP version (pre-7.3), use this more compatible check that verifies the value is either an array or a Countable object:
$term_count = (is_array($some_variable) || $some_variable instanceof Countable) ? count($some_variable) : 0;Save the file, then refresh your site to confirm the warning is gone.
A quick note: Always make a backup of the plugin file before modifying it — just in case you need to revert changes later. Since the plugin is discontinued, you don't have to worry about updates overwriting your fix.
内容的提问来源于stack exchange,提问作者lukehillonline

