Warning: count(): Parameter must be an array or an object that implements Countable

Jim asked 2 weeks ago

With Cherry Framework 3.1.5 and using PHP 7.2, getting this error in WordPress backend on Cherry Options page:
Warning: count(): Parameter must be an array or an object that implements Countable in /folder/folder/folder/folder/wp-content/themes/CherryFramework/admin/options-medialibrary-uploader.php on line 217
Thoughts on how to fix?
Line 217 is: if ( count( $_posts ) ) {
The surrounding code is:
// Look in the database for a “silent” post that meets our criteria.
$query = ‘SELECT ID FROM ‘ . $wpdb->posts . ‘ WHERE post_parent = 0’;
foreach ( $_args as $k => $v ) {
$query .= ‘ AND ‘ . $k . ‘ = “‘ . $v . ‘”‘;
} // End FOREACH Loop

$query .= ‘ LIMIT 1’;
$_posts = $wpdb->get_row( $query );

// If we’ve got a post, loop through and get it’s ID.
if ( count( $_posts ) ) {      //This is line 217
$_id = $_posts->ID;
} else {

// If no post is present, insert one.
// Prepare some additional data to go with the post insertion.
$_words = explode( ‘_’, $_token );
$_title = join( ‘ ‘, $_words );
$_title = ucwords( $_title );
$_post_data = array( ‘post_title’ => $_title );
$_post_data = array_merge( $_post_data, $_args );
$_id = wp_insert_post( $_post_data );
 
 

Your Answer

18 + 12 =