the_content(); of custom post type treated as an array or object

I created a custom post type in the mu-plugins folder.

function wpdocs_codex_book_init() {
$labels = array(
‘name’ => _x( ‘Books’, ‘Post type general name’, ‘textdomain’ ),
‘singular_name’ => _x( ‘book’, ‘Post type singular name’, ‘textdomain’ ),
);

$args = array(
‘labels’ => $labels,
‘public’ => true,
);

register_post_type( ‘book’, $args );
}

add_action( ‘init’, ‘wpdocs_codex_book_init’ );

When it comes to render the content of it in the single-book.php page I create the custom query and I use this code:

<?php
$args = array(
‘post_type’ => ‘book’,
);
$query = new WP_Query( $args );
?>

<h1><?php the_title(); ?></h1>
<h1><?php the_content(); ?></h1>

the title is rendered correctly but when it comes to the content it throws this error:

Warning: count(): Parameter must be an array or an object that
implements Countable in /app/public/wp-includes/post-template.php on
line 284

The default posts and the pages are, instead, rendered correctly. Why is this happening? Thanks in advance

Read more here:: the_content(); of custom post type treated as an array or object

Leave a Reply

Your email address will not be published. Required fields are marked *