Jump to content

Recommended Posts

I've got 2 error messages after I set up a new wordpress installation & installed the knowledge template. It's the first time for me to setup a wordpress page & template. I'm not that known in php and i didn't find a solution for this.

So here u can see the error messages live: https://www.kassen.de/knowledge/knowledge-base/

The Errormessages are:

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/37/d157950258/htdocs/knowledge/wp-content/themes/knowledgepress/template-knowledgebase.php on line 98

and

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/37/d157950258/htdocs/knowledge/wp-content/themes/knowledgepress/template-knowledgebase.php on line 116

And this is the code from the php files on the specific lines:

Line98:

if(count($subcategories)==0 && count($cat_posts)==0){ continue; }

Line 116:

if(count($subcategories)>0) { foreach($subcategories as $sub_category) { $term_id[] = $sub_category->term_id; ?>

Does someone has a solution for this? This would be awesome!

Greetings :)

Seeing as $subcategories is the common variable on both lines, I'd assume that is the problem. As of 7.2, php starting emitting a warning if the variable passed to count() isn't an array or another type that actually can be counted. I don't know what the 'knowledge template' is, but I'd bet it was developed before php7, and that sometimes there are no subcategories - this is probably leaving $subcategories null or 0, which isn't countable. Check to see if there's an updated version of the theme; if not you'll need to find where $subcategories is defined and make sure it's an array even if there aren't any subcategories to be found.

So this is the template for wordpress. https://themeforest.net/item/knowledge-base-helpdesk-wiki-faq-wordpress-theme/3434096

On the webserver i use MariaDB 10.5.

The problem is, i've never done something with php. Only with html, css. I added categories in the wordpress backend but im not sure where this error comes from, or how i can fix that. 😕

The code just prior to those lines needs to check if the subcategories var is an array, or even if it is 'set'.  If it is not then you need to code around that logic to avoid the invalid testing that's happening.

Actually - upon further review - do a test of the var prior to the use of count and if it is not set add this line:

if (!isset($subcategories))
   $subcategories = array();

Now you have a countable variable that should solve both errors.

Edited by ginerjm

Maxxd and ginerjm pretty much nailed it.  The warning was introduced in PHP version 7.2.

Is it possible you can get an updated version of the template you are using?  You might need to make a lot of these types of patches.

I'd probably make this variation on ginerjm's fix:

$subcategories = empty($subcategories) ? array() : $subcategories;

 

Just getting back to this. According to the ThemeForest page the last update to this theme was in 2018. A lot has happened in both PHP and WordPress since then - it might be time to start shopping for a new theme. I can almost guarantee that if you're seeing these issues now you're going to see worse issues with the code in the future.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.