I'm currently working with php 7.2 and when I use get_the_content() or get_the_excerpt() outside of a single template, in the functions.php for example, I get the following Warning:

Warning: count(): Parameter must be an array or an object that implements Countable in /Applications/MAMP/htdocs/wordpress/wp-kona/wp-includes/post-template.php on line 284

What's wrong with it? Is it a wordpress core bug? Am I missing something.

  • What is your full use of the function? – Jacob Peattie Mar 21 at 11:45
  • 1
    Are you calling these functions outside the loop? – kero Mar 21 at 11:47
  • I think this is unimportant. I'm just using it to check if the content has some specefic shortcode for example. Yes, it's outside the loop. But how can I access to the content (with the id) then outside the loop. – Benmay Mar 21 at 11:49
  • 1
    Can you show the specific usage that is causing the issue. To rule out any syntax issues or incorrect usage of the function. – Jacob Peattie Mar 21 at 11:50
  • This is a bug in core WP. See core.trac.wordpress.org/ticket/42814 – Nathan Johnson Mar 21 at 15:23

This bug related to WordPress core bug https://core.trac.wordpress.org/ticket/42814

Most often it occurs when you call the function get_the_excerpt or get_the_content outside the Loop provided that excerpt or content is empty.

So to fix it yourself you should find error place and check excerpt/content existing manually.

For example:

if(has_excerpt($post_id)) {
    $meta[] = sprintf('<meta name="description" content="%s">',

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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