Skip Navigation

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

Problem:
The client was experiencing a crash when trying to create a normal post in a custom post type, specifically when there were no posts in the custom post type.

Uncaught TypeError: 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:26

Solution:
We recommend adding a conditional check to the relevant file to prevent the crash. Insert the following code to the file

/wp-content/plugins/sitepress-multilingual-cms/menu/post-menus/wpml-posts-listing-page.class

at line 25:

if (empty($wp_query->posts)) return;

This code ensures that if there are no posts, the function will return early and prevent the crash.

Please note that this solution might be outdated or not applicable to your case. If you're still experiencing issues, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket with us.

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 5 replies, has 3 voices.

Last updated by Long Nguyen 9 months, 1 week ago.

Assisted by: Long Nguyen.

Author Posts
February 2, 2024 at 10:33 am #15258606

Matteo Canever

I am trying to: create a normal post in a custom post type

Link to a page where the issue can be seen: see screenshot

I expected to see: no crash

Instead, I got: a crash

Wordpress 6.4.2
Wordpress multisite subfolder
WPML Multilingual CMS Version 4.6.9
WPML String Translation Version 3.2.9

The expected fix is to edit the file (in the screenshot), add this in line 26
```
if ( empty($wp_query->posts) )
return;
```
Or make sure that if it is NULL then do return.

Screenshot_20240202_182503.png
February 2, 2024 at 1:05 pm #15259389

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello, welcome to the WPML Support forum!

While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with first debugging steps or if I can perhaps help with the issue quickly.

Please try the following workaround:
- Open the wp-content/plugins/sitepress-multilingual-cms/classes/wp-core-hooks/post/class-wpml-remove-pages-not-in-current-language.php file
- Around line 34, replace the following snippet:

$filtered_posts   = $posts;

With

$posts = (isset($posts) && is_array($posts)) ? $posts : array();

Please let us know if it worked. We will need to notify our development team.

February 7, 2024 at 2:38 am #15274239

Matteo Canever

Hello, i already had a workaround based on my initial post.
I just need this to be fixed in your next release soon. Thanks in advance.

February 7, 2024 at 4:18 am #15274266

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi Matteo,

Thank you for your feedback and workaround.

Can you please share a backup of your site and database so I can escalate the issue to the development team to take a further look? Your next reply is set to private to share the info.
You can use this plugin to create the backup: https://wordpress.org/plugins/duplicator/
https://wordpress.org/plugins/all-in-one-wp-migration/

Note: you can exclude some unneccessary folders from the backup file such as /wp-content/uploads/, /wp-content/cache/ ... to reduce the file size.

Look forward to your reply.
Thanks

February 8, 2024 at 1:43 am #15279465

Matteo Canever

Hello, I cannot give you a backup since I already moved on from this issue. I already applied the workaround and I'm just sharing to you that there is this problem where a crash can occur.
The crash occurs when there is no posts inside a custom post type, not sure why it does occur but more info is in the screenshot.
I'm assuming it is clear in the screenshot and based on the workarounds suggested.
If you assume that the info I'm sharing is not substantive enough, then you can just close this support issue.

February 9, 2024 at 7:10 am #15284149

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I will share your workaround with our users if I see the same error. Feel free to contact us again if you have more questions.

Thanks.