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

Sebastian Graus
Sebastian Graus
633 Points

Custom Post Types and Custom Fields not showing up

Hi,

I'm right now following Zac Gordon 's tutorial on creating custom post types and custom fields. I've filled everything in in the Custom Post Types plugin and the Custom Fields Plugin. The problem is that they don't show up, they are not even included in the source-code if I right-click and click view source code in google crome. Here's the page: http://marielaveau.se/wordpress/bar/ . Apparently it's not including only the php code, as the text "This is the bar.php file" is showing up.

Here's the entire code for my page:

<?php 

/* Template Name: Bar */

 ?>

<?php get_header(); ?>
<p>This is the bar.php file</p>

<?php

$sargs = array(
    'post_type' => 'sidor'

    );

$the_query = new WP_Query( $args );

?>

<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();                                ?>
     <h1><?php the_title(); ?></h1>
    <?php the_field( 'beskrivning' ); ?>




<?php endwhile; else: ?>
    <p><?php _e('Ledsen, sidan du försöker hitta finns inte.'); ?></p>
<?php endif; ?>
</div>

<?php get_footer(); ?>

So why is this not working, and why is the code not showing up in the source code? I don't get any syntax errors in my editor so it seems as if the php code is written properly.

6 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

When you change the comment at the top to read

/*

    Template Name: Bar

*/

Does that change anything? Sometimes just the line spacing can make a difference.

Joseph Burdick
Joseph Burdick
11,543 Points

I'm having a similar issue. It appears that in the video Displaying Custom Posts and Fields that there's a missing piece that explains where the "plugin" for the custom fields is introduced. On my Wordpress admin sidebar I don't see Custom Fields even though I've been following along.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Did you install the custom fields and post types UI plugins?

Joseph Burdick
Joseph Burdick
11,543 Points

Zac,

I didn't and that's probably the issue, thanks for pointing that out. Thing is I thought I watched all these videos in succession, do you know which video it is that you discuss these two plugins?

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

It's at the end of one of the first ones when we're talking about content :) you're not the first person to miss it, don't worry ;)

Hi Zac,

I had the same issue, it appears that the 'Adding custom content to the site' video at the end of the 'Content Strategy with Wordpress' section was automatically skipped for me.