Site icon Hip-Hop Website Design and Development

Advanced Custom Fields: single-books.php works, books.php does not

I’m using CPT UI to create the post type (books). I am running in debug mode. This is all happening on default, WordPress 3.8, twenty twelve theme.

I created a field group called Books in ACF and added three fields: book_title, book_author, pub_year. I set the field group to show if post type is books. I then copied page.php, renamed it books.php, and replaced the default header with Template Name: Books. I created a new page called Book Entries and set the template style to Books. I added this page to the menu. I added the necessary php script in books.php to show the post data. I then used Add Books to enter four different sample book titles using the custom fields and saved them. I am able to view them individually on single-books.php, but when I go to Book Entries I see… no post data. I see everything else, like title, header, footer, sidebars, comments, but no post data.

Below is the code for books.php:

<?php
/**
 * Template Name: Books
 *
 *
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header(); ?>

    <div id="primary" class="site-content">
        <div id="content" role="main">
<?php if ( have_posts() ) : ?>
                <h1><?php the_field('book_title'); ?></h1>
                <h2><?php the_field('book_author'); ?></h2>
                <p><?php the_field('pub_year'); ?></p>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'page' ); ?>

                <?php comments_template( '', true ); ?>
            <?php endwhile; // end of the loop. ?>
<?php endif; wp_reset_postdata(); ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>