How to Show Custom Post Type on WordPress Template

So you have created a custom post type and you may have figured how to add it’s post count on dashboard, you are probably wondering how to actually render it on front-end.

So these are the things you have to do.

First,

Create a template. You can typically use the single.php template but wouldn’t it be nice if you’ll create a separate template just to render this?

So create a template and name it ‘single-custom_post_type_name.php’. In my case, I created single-portfolio.php since my
custom_post_type name is portfolio.

Second,

Add the code to render the data to the front-end of your site. You can just actually copy and paste your code from single.php. Same code works as how you render the default WordPress posts.

Last,

Things don’t work aye? It is because you have to flush the permalinks.

Go to Settings > Permalinks > Save. Just like that. You just have to flush the defaults. This is where most developers really had the hard time figuring out because everything should work.

After you’ve done it, open a single custom post or reload it. It should work now.

Leave a Reply

Your email address will not be published. Required fields are marked *