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. 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

Sign up to request clarification or add additional context in comments.

1 Comment

That fixed it! Thank you.
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 {

Comments

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.