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 trialwhsmyzszcd
1,322 PointsCustom Post Types: Fields not displaying on page
Following along with the custom post types instructions, I created the new custom post types using the Custom Fields and Custom Post Type UI plugins. For the last lesson, I uploaded the .php files for the custom template using FTP.
On my Art page, the fields seem to be displaying, but the actual content isn't. For example, I took a screenshot of how it was showing for me and you can see that the description of the image is shown, along with the price field, but neither the image or numerical price are actually showing on the page: http://wp.me/a4roS9-n
You can go directly to the page here: http://treehouse.ericavarlese.com/?page_id=18
Any tips or suggestions on troubleshooting? I didn't change any of the project files, so the only difference I can see is just that I'm using Twenty Twelve as the parent theme.
Thanks for any help you can give!
3 Answers
Zac Gordon
Treehouse Guest TeacherCan you post up the code you're using please :)
I am guessing something is off with either the custom query or the the_filed() tags being used.
whsmyzszcd
1,322 PointsThanks Zac!
In content-art.php, I've got:
<?php
/**
* Template for displaying art custom post type entries
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<div class="entry-meta">
<p>Price: $<?php the_field('price'); ?></p>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<p><img src="<?php the_field('image'); ?>" alt="Example image of <?php the_title(); ?>"></p>
<p><?php the_field('description'); ?></p>
</div><!-- .entry-content -->
</article><!-- #post -->
And in art.php, I have:
<?php
/**
* Template Name: Art Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php //comments_template(); ?>
<?php endwhile; ?>
<?php
$args = array(
'post_type' => 'art',
'orderby' => 'title',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'art' ); ?>
<?php endwhile; endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Anthony Moore
2,282 PointsHi Erica,
In your content-art.php can you try using
<p>Price: $<?php echo get_post_meta( get_the_ID(), 'price', true ); ?></p>
and see if the price shows up?