Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing a fatal error when enabling Redis Object Cache on your WordPress site, specifically with PHP 8+ where count() is called on a null value in WPML_Posts_Listing_Page::pre_populate_caches(), this might be due to a cache miss causing

$wp_query->posts

to be null. This error typically appears in wp-content/plugins/sitepress-multilingual-cms/menu/post-menus/wpml-posts-listing-page.class.php on line 26.
Solution:
We recommend updating to WPML version 4.7.5, which addresses this issue by ensuring compatibility with Redis Object Cache and other object cache implementations. You can download the update and view the changelog here: WPML Changelog.

If this solution does not apply to your case, or if it seems outdated, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If issues persist, we highly recommend opening a new support ticket for further assistance.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 7 replies, has 0 voices.

Last updated by serhiiR 1 week, 1 day ago.

Assisted by: Christopher Amirian.

Author Posts
April 16, 2025 at 9:04 am #16937294

serhiiR

Background of the issue:
I am trying to enable Redis Object Cache on my WordPress site. When Redis Object Cache is active, count() is called on a null value in WPML_Posts_Listing_Page::pre_populate_caches(), resulting in a fatal error in PHP 8+. I followed these steps: 1. Enable Redis Object Cache. 2. Go to /wp-admin/edit.php (Posts/Pages screen). A fatal error may occur unpredictably due to a cache miss. The error occurs in wp-content/plugins/sitepress-multilingual-cms/menu/post-menus/wpml-posts-listing-page.class.php on line 26. The root cause is that under object caching (e.g., Redis), $wp_query->posts may be null due to a cache miss. Calling count(null) causes a fatal error in PHP 8+. Suggested fix: Please wrap the count() call in a type check: if ( empty( $wp_query->posts ) || ! is_array( $wp_query->posts ) ) { return; } This makes the method safe and compatible with any object cache implementation.

Symptoms:
Fatal error: count(): Argument #1 ($value) must be of type Countable|array, null given in wp-content/plugins/sitepress-multilingual-cms/menu/post-menus/wpml-posts-listing-page.class.php on line 26.

Questions:
How can I prevent the fatal error when Redis Object Cache is enabled?
What is the correct way to handle null values in WPML_Posts_Listing_Page::pre_populate_caches()?

April 17, 2025 at 2:30 pm #16944537

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Welcome to WPML support. Thank you for the error report and the suggestion.

Before we can go forward, we need to make sure the problem happens in a minimal installation firs,t as adding that Empty check in PHP might have other implications that we are not aware.

If we can replicate the issue on a minimal installation, we will be able to report this and then the second-tier support will check.

- IMPORTANT STEP! Create a backup of your website. Or better approach will be to test this on a copy/staging version of the website to avoid any disruption of a live website.
- Switch to the default theme such as "TwentyTwenty" by going to "WordPress Dashboard > Appearance > themes".
- Go to "WordPress Dashboard > Plugins" and deactivate all plugins except Redis cache, WPML and its add-ons.
- Check if you can still recreate the issue.
- If not, re-activate your plugins one by one and check the issue each time to find out the plugin that causes the problem.

If the issue persists on a minimal installation, I'd aprpeciate it if you could give us login information for a copy/staging version of the website so we can check and if needed report?

Thanks.

April 18, 2025 at 11:17 am #16947087

serhiiR

Hi,

Thanks for the detailed reply.

I followed your instructions and switched to the default Twenty Twenty-Five theme. I also deactivated all plugins except Redis Object Cache, WPML, and its official add-ons.

Unfortunately, the issue still occurs in this minimal setup. The only ways to avoid the fatal error are:
• Disabling Redis Object Cache, or
• Disabling WPML, or
• Applying the code fix I proposed earlier.

This confirms that the bug lies in the interaction between WPML and object caching, not a third-party plugin or theme.

At the moment, I don’t have a remote (non-local) staging copy of the site I can share access to. However, I’ve recorded a short video demonstrating the issue exactly as described — let me know if you’d like me to send it over.

Thanks again — happy to help test any patches or provide more info.

April 20, 2025 at 2:06 pm #16949912

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Thank you for the information. Please use one of the third party transfer websites such as wetransfer and share the link to the video here.

Now that you managed to see the issue without the interference of other themes or plugins, it will be great if you could do the same on a clean installation of WPML and WordPress.

That way, I will be able to report this to the compatibility team.

To be able to report the compatibility issues we need to replicate the issue on a clean installation.

I created a clean installation of WordPress, WPML, and all necessary WPML add-ons.

You can access the WordPress dashboard using the link below:

hidden link

Kindly follow the steps below:

- Install Object Cache plugin
- Try to replicate the issue.
- Get back to us with the steps to replicate the issue

This will help us to report the probable issue to the compatibility team and solve the possible problem faster.

Thanks.

April 27, 2025 at 3:05 pm #16972440

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Thank you and sorry for the late reply.

Unfortunately, the video link does not work for me. Would you please use loom.com to create a video and share it with us?

Also I will need to know what are the settings you do on the server level to be able to replicate the same thing on our side.

Thanks.

April 28, 2025 at 8:11 am #16973561

serhiiR

Hi,

Thank you for your reply, and no worries about the delay.

Regarding the video — I’ve actually set up everything on the provided sandbox server, so you don’t necessarily need a video.

However, here’s the video link via OneDrive: hidden link, just in case it’s helpful.

There are no special server configurations involved — it’s simply:
- Redis installed via sudo apt install redis-server -y with default settings,
- The Redis Object Cache plugin by Till Krüss,
- And minimal configuration in wp-config.php:

define('WP_CACHE', true);
define('WP_CACHE_KEY_SALT', 'wiki_');
define('WP_REDIS_DATABASE', 0);

At this point, I believe we are spending too much time verifying plugins and environment settings.

Instead, I’d like to focus on a more fundamental question:
Is it expected that the pre_populate_caches() function doesn’t handle null values properly, regardless of the reason they occur? Currently, if null is passed, the function leads to either a warning or a fatal error depending on the PHP version.

Looking forward to your thoughts on this.

Thanks again!

April 30, 2025 at 1:43 pm #16984278

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hello,

Thank you very much for the details. Would you please check the video below?

hidden link

Do I miss something here? That is important to know if the issue happens when only WPML and Onject cahe is presented or other plugins might have a say here.

Thanks.

May 1, 2025 at 4:30 pm #16987054

serhiiR

Hi,

Thanks a lot for recording the video!

I’ll admit I don’t fully understand how Object Cache works internally, so take this as a hypothesis.

I think the key difference in my case is the absence of pages. We use post_type=post, but don’t use post_type=page at all.

My guess is that the fatal error happens on edit.php?post_type=page when there are no pages in the database, and count() can’t handle that. It’s possible that result might get cached and later affects other screens, including edit.php?post_type=post. That said, on the clean test setup, I wasn’t able to reproduce the issue on edit.php?post_type=post.

However, after removing the pages you had created, I could reproduce this error again on edit.php?post_type=page, though only after refreshing the page a few times. On the current PHP version, it shows as a warning instead of a fatal error.

Thanks.

CleanShot 2025-05-01 at 19.29.01.png
May 2, 2025 at 8:59 am #16988608

serhiiR

A quick update: I upgraded the production site to WordPress 6.8.1 and WPML Multilingual CMS 4.7.4 today.
The critical error still occurs on /edit.php?post_type=page when no pages exist.

However, creating a single page (even a draft) prevents the error from appearing.
That said, this feels more like a workaround than a proper fix.

May 4, 2025 at 2:18 pm #16993316

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

Thank you for that clever point! I do agree that it is a mere workaround rather than a solution.

I'd appreciate it if you could keep that test site up so I can report this to the compatibility team as it pertains to a third-party cache system.

I will get back to you if I have news from the compatibility team.

Meanwhile, I'd appreciate it if you could keep one draft page there to continue your normal work for the time being.

Thanks

May 5, 2025 at 7:57 am #16995032

serhiiR

Hi, thanks!
I’ll keep the test site online for now and leave a draft page as suggested.

Looking forward to any updates.

May 5, 2025 at 2:37 pm #16996892

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Thanks. I will update as soon as I have news.

May 14, 2025 at 12:31 pm #17032270

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

The issue fix will be available on version 4.7.5 or at most 4.7.6.

We change this ticket status to will be fixed in the next release.

Thank you.

May 26, 2025 at 8:10 am #17071470

Christopher Amirian
WPML Supporter since 07/2020

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi,

The issue is fixed on WPML version 4.7.5 which is already released:

https://wpml.org/download/wpml-multilingual-cms/?section=changelog

Thanks.

May 26, 2025 at 4:34 pm #17074455

serhiiR

I’ve updated to version 4.7.5, and everything is working great now. Thanks a lot!