Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Make a Website with WordPress Custom Post Types and Fields in WordPress Custom Post Type Templates

Gabriel Ward
Gabriel Ward
20,222 Points

Custom Post Type Template

I'm doing this tutorial with the twentyfourteen theme. I've got things working fine, but initially I had this in my single-art.php, and it didn't work.

<?php


get_header(); ?>

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
            <?php
                // Start the Loop.
                while ( have_posts() ) : the_post();

                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                    get_template_part( 'content', 'art'() );

                    // Previous/next post navigation.
                    twentyfourteen_post_nav();

                    // If comments are open or we have at least one comment, load up the comment template.
                    if ( comments_open() || get_comments_number() ) {
                        comments_template();
                    }
                endwhile;
            ?>
        </div><!-- #content -->
    </div><!-- #primary -->

<?php
get_sidebar( 'content' );
get_sidebar();
get_footer();

When I changed

get_template_part( 'content', 'art'() );

to

get_template_part( 'content', 'art' );

it worked. Would anyone be able to explain to me why removing the brackets made things work as they should? I'm just wanting to improve my own understanding. Thanks.

1 Answer

Thiago Ponte
Thiago Ponte
1,373 Points

If you look here: https://codex.wordpress.org/Function_Reference/get_template_part You will see that the second parameters is a string, not a function. That extra () must have been just a mistype.