I updated four of my websites with the new HivePress update, and one of them had a small “hiccup.” Not sure why, but I was able to use ChatGPT to create a quick fix. I figured I’d share it here in case it helps anyone else. I wasn’t even going to bother posting since it only happened on one site, but it created a pretty major issue where users couldn’t register, submit a listing, or edit a listing — and this code snippet fixed it.
Temporary Fix Included — PHP 8.4 + HivePress Fatal Error
One of my HivePress sites running PHP 8.4 was throwing the following fatal error on:
-
Submit Listing
-
Register Vendor
-
Editing a listing
count(): Argument #1 ($value) must be of type Countable|array, null given
in /wp-includes/class-wp-query.php:3564
To diagnose it, I tested with:
-
Only HivePress active
-
A default theme (Twenty-One)
-
All custom code disabled
…and the issue still occurred.
It appears that in certain situations, posts_results returns null on PHP 8.4, and then WP_Query calls count() on that null value, causing the fatal.
Temporary Fix (working perfectly)
add_filter( 'posts_results', function( $posts, $query ) {
if ( $posts === null ) {
return [];
}
return $posts;
}, 9999, 2 );
This simply forces the filter to always return an array instead of null, which prevents the PHP 8.4 fatal error.
Just sharing in case it helps someone else — or if the HivePress team wants to add a similar guard for PHP 8.4 compatibility.
Thanks for the great plugin!
