PHP 8.4 + HivePress → posts_results returning null (critical error)

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.


:white_check_mark: 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!

2 Likes

Hi,

Thank you for the detailed bug report. Unfortunately, we weren’t able to replicate it locally [tried on PHP 8.4.4 and 8.4.10]. Is there a chance that something specific can cause it? For example, have you tried temporarily disabling any custom attributes to see if that affects the issue?

Could you please also share the version of WordPress you’re using?

It appears to be the same on my end

Hi Kseniia,

I’m running Wordpress -

Version 6.8.3

On the site that had the issue. The other sites didn’t have the issue as I mentioned and I’m not sure what caused the issue other than what I shared from CHAT GPT that wrote the Code Snippet for me to resolve the issue.

Thanks again,

John

Hi Paperboy,

That was the same message that I had on one of my sites when I went to submit-listing or register-vendor, which is why I posted the issue here. The Code Snippet that I installed and shared resolved the issue.

Hopefully, that will work for you as well.

1 Like

Hello,

I updated last Sunday to version 1.7.17, and now all the options in the user menu (when the user is logged in) no longer work. They show a generic WordPress error page.

I have already deactivated active plugins as well as code snippets. I would like to know if this is a known issue.

Steps to reproduce

  • Update from 1.7.16 to 1.7.17

Actual result

  • Errors when accessing the user menu

Expected result

  • No impact on the user menu

Extra details

Hi,

Thanks for reporting the issue. Please let me know if there are any prerequisites to reproduce it, have you added or removed any listing attributes, or maybe other content (vendor profiles, for example) before it started occurring?

If you also have a full stack trace of the error (usually logged in the PHP error log), please post it: How to configure WordPress error logs to identify and resolve problems - HivePress Help Center. Also, does the mentioned email contain any helpful information regarding the error?

If there’s a bug, we’ll provide a temporary fix and release a fix for it later.

1 Like

Hi,

Thanks for your reply.

There are no prerequisites; I haven’t changed any code snippets or added new plugins for months. I’ve also updated HivePress successfully during this time, up to version 1.7.17.

After reverting to 1.7.16, everything is working fine.

I’m going to check the error logs you mentioned and try setting up a mock environment to reproduce the issue.

I’ll keep in touch.

Thanks and best regards,

1 Like

Hi,

As requested, I have enabled the debug log. Here is the relevant output:

PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
in /home/a/www/wp-includes/class-wp-query.php:3564
Stack trace:
#0 /home/a/www/wp-includes/class-wp-query.php(3949): WP_Query->get_posts()
#1 /home/a/www/wp-includes/class-wp.php(701): WP_Query->query(Array)
#2 /home/a/www/wp-includes/class-wp.php(821): WP->query_posts()
#3 /home/a/www/wp-includes/functions.php(1342): WP->main(‘’)
#4 /home/a/www/wp-blog-header.php(16): require(‘/home/a/www/wp-blog-header.php’)
#5 {main} thrown in /home/a/www/wp-includes/class-wp-query.php on line 3564

I have noticed that in version 1.7.17, the set_post() method signature has changed to:

public function set_post($current_post, $force = true)

and includes the following code:

if ( $post && ! $force ) {
return;
}

Could this modification be causing the count(): Argument #1 must be of type Countable|array, null given error in WP_Query?

Version 1.7.16 works fine,

Thanks and Best regards,

Thank you for the details.

Could you please also share your PHP and WordPress versions so we can test it with the correct configurations?

Hi Kseniia,

Sure! Here are the details:

WP: 6.8.3
PHP Version: 8.0.30

Best regards,

For your information, and in case it helps, I have temporarily “resolved” the problem by adding this filter to functions.php (I don’t know if it could cause new issues, but it seems to work):

add_filter( 'posts_results', function( $posts, $query ) {
    if ( $posts === null ) {
        return [];
    }
    return $posts;
}, 10, 2 );

I’m not sure if this is the cause of the issue, but I’ve noticed that all pages in the user menu, such as listings_edit_page, messages_thread_page, and user_edit_settings_page, seem to be treated as post pages by WordPress. Could this be related to the recent changes in HivePress version 17, specifically the disable_page_query filter in class-router.php?

On these pages, WP_Query sometimes returns null, which causes a fatal error when count() is called in class-wp-query.php. Other pages, like public listings or categories, appear to work correctly.

I wanted to share this observation, even though I’m not certain it’s correct, in case it helps

Thanks and best regards,

1 Like

Thank you for the update.
If you don’t mind, I will merge this topic with an existing one so we can keep track of the issue in one place.

1 Like

Hi,

Thank you for the details. We’ll release the fix as soon as possible.

1 Like

A few days ago, an error started appearing when I tried to publish ads. The error message says, “There has been a critical error on this website.”
This week, I only added some new tools created with HTML, CSS, and JavaScript, which I copied into the custom HTML section of WordPress and placed in the tools section.

I deactivated some plugins, but the error persists.

My PHP version is 8.2

The result of debug.log is:

\[30-Nov-2025 01:04:33 UTC\] PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/u235105174/domains/nexempleo.com/public_html/wp-includes/class-wp-query.php:3564
Stack trace:
#0 /home/u235105174/domains/nexempleo.com/public_html/wp-includes/class-wp-query.php(3949): WP_Query->get_posts()
#1 /home/u235105174/domains/nexempleo.com/public_html/wp-includes/class-wp.php(701): WP_Query->query()
#2 /home/u235105174/domains/nexempleo.com/public_html/wp-includes/class-wp.php(821): WP->query_posts()
#3 /home/u235105174/domains/nexempleo.com/public_html/wp-includes/functions.php(1342): WP->main()
#4 /home/u235105174/domains/nexempleo.com/public_html/wp-blog-header.php(16): wp()
#5 /home/u235105174/domains/nexempleo.com/public_html/index.php(17): require(‘/home/u23510517…’)
#6 {main}
thrown in /home/u235105174/domains/nexempleo.com/public_html/wp-includes/class-wp-query.php on line 3564

Does anyone know the cause?

I have reinstalled WordPress, disabled the plugins, changed the theme, and cleared the cache, and I have removed the custom HTML script.
The error persists on the page:

In a previous post, I mentioned issues with the functionality of the Hivepress plugin, but I wasn’t sure of their origin. I restored a website backup, and when I updated to version 1.7.17, the plugin stopped working.

Hi,

Thank you for reporting the issue. We are working on it and will release the fix in the future update.

As a temporary solution, please use the code snippet that is provided in the topic.

Thank you for your patience.

1 Like

Please let me know