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

Adam Smallman
Adam Smallman
4,182 Points

Wordpress adding new fields and posts

Hi guys, again

So I have been through much of how to build a wordpress theme, No issues with following the videos but I have tried to give it a try away from the video.

I did what I did in the video, got the two plugins Custom Fields and CPT UI

I have created a new post in CPT UI called 'showreel' in Custom Fields I have created a few fields called title of showreel image and description

I can create a new post? I think its called under the showreel like a new blog post. asking for the right things, a title, an image and a text area description no problem.

So I then turn to the code to try and show it on the front-page.php

in the video Zac uses the_post and have_posts, using this will show the posts post. as expected.

So trying to copy the above my front-page.php looks like this

```<?php get_header() ?> <p>I am the mainpage </p>

<?php if ( have_showreel ( ) ) : while ( have_showreel ( ) ) : the_showreel ( ) ; ?>
<h3><?php title_of_showreel() ;?></h3>
<?php the_content(); ?>
<hr>

<?php endwhile; else: ?> <p>There are no posts </p> <?php endif; ?> <?php get_footer() ?>```

this comes up with the following when in wordpress,

This is the header.php

I am the mainpage

Fatal error: Call to undefined function have_showreel() in /home/loki180/public_html/wp-content/themes/wpdance/front-page.php on line 4

So I am guessing it does not know what have_showreal means. I am confused on how to do this.

I have been looking through past videos I have watched to find the answer but could not find anything yet.

Thanks for any help

1 Answer

You would still use the have_posts() ,function even for custom posts. Since you've not (I assume) created a new function called have_posts. It's the arguments for the query that are tied to the custom post type. e.g. http://wordpress.org/support/topic/listing-posts-from-a-custom-post-type

Adam Smallman
Adam Smallman
4,182 Points

I knew it was going to be something stupid I missed out,

Thanks Andrew