3

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 {
1
  • accept my edit. your question looks bad without an edit.
    – Ahtisham
    Commented Jan 26, 2019 at 18:40

3 Answers 3

5

$_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

1
  • 1
    That fixed it! Thank you. Commented Jan 26, 2019 at 18:34
2

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 {
0

http://php.net/manual/en/function.count.php

You can use is_countable() function in php to check whether an object supports count functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.