Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP error: Warning: count(): Parameter must be an array or an object that implements Countable

Tags:

php

wordpress

I updated my Wordpress site from PHP 5.6 to 7.2 and noticed an error in my Wordpress backend after the update. It says:

Warning:  count(): Parameter must be an array or an object that implements 
Countable in <b>/homepages/36/d362586048/htdocs/genag/wp- 
content/themes/genag- 
theme/framework/admin/functions/functions.mediauploader.php on line 127

I have included the code from that line and 2 lines below it. Any help would be appreciated.

if ( count( $_posts ) ) {
$_id = $_posts->ID;
} else {
like image 599
user3612498 Avatar asked Feb 10 '26 20:02

user3612498


2 Answers

$_posts appears to be an object, you should use it like an object $_posts->ID. So it cannot be counted like an array.

if ( $_posts ) {

Should do the job

like image 117
Matthew Page Avatar answered Feb 13 '26 08:02

Matthew Page


In PHP 7.2, count() method does not support Null as a parameter.

I have got the same error, in one of my old Avada theme based wordpress website.

I have solved it using the following modification.

if ( (!empty($_posts)) && (count( $_posts ) ) { $_id = $_posts->ID; } else {
like image 30
Dakshim Chhabra Avatar answered Feb 13 '26 10:02

Dakshim Chhabra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!