Support » Fixing WordPress » PHP warning from programmatically creating posts

  • I get the PHP warning Warning: count(): Parameter must be an array or an object that implements Countable in /path/to/wordpress/wp-includes/post-template.php on line 293 every time I programmatically create a post with wp_insert_post().

    If I go back into the post via the admin UI and update it, the warning goes away.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter good3n

    (@good3n)

    If I edit the WP core file post-template.php

    Before (Warning):

    
    if ( $page > count( $pages ) ) { // if the requested page doesn't exist
      $page = count( $pages ); // give them the highest numbered page that DOES exist
    }
    

    to this..

    After (No Warning)

    
    if(!empty($pages)) {
      if ( $page > count( $pages ) ) { // if the requested page doesn't exist
        $page = count( $pages ); // give them the highest numbered page that DOES exist
      }
    }
    

    Then everything is good. Is this a bug in WP core?

    It certainly looks like it. PHP 7.2 started this warning. There was an attempt to find all the places in the code where that was happening, but apparently this one was missed.
    Can you write a ticket for it? (search first)
    https://core.trac.wordpress.org/

    Thread Starter good3n

    (@good3n)

    Thanks Joy.

    danielthechannel

    (@danielthechannel)

    I’m having this same error message come up on my site.

    @good3n – did you get a fix for it?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP warning from programmatically creating posts’ is closed to new replies.