https://fisherinc.co.uk/wp-content/uploads/youtube-video-thumbnail-03.jpg

How to Setup Custom Post Types in WordPress

  • WP Tutorials
  • 18/06/17
  • 02:03 PM
  • AMP
Fisher INC ltd How to Setup Custom Post Types in WordPress 18/06/17
Custom Post Types WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored […]

Custom Post Types

WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type

WordPress Post Types

In this tutorial I’m going to be showing you how to add Custom Post Types to your WordPress site.

We can use custom post types to separate post into dedicated sections on our site, separate from posts / pages.

In this instance we going to make a testimonial section on our WordPress site where we can house all the testimonials we get from clients.

custom post type

Step 1

Go to your themes functions.php file, To get there You can go via Appearance –> Editor and look for functions.php or theme functions or you can use a code editor and edit your themes function.php file directly via Wp-Content –> Themes –> Your Theme –> functions.php.

Before editing please take a backup of the file you are working on In case anything goes wrong.

Step 2

At the bottom of your functions.php add the following code to register the custom post type.

The $labels Is an array of strings which are used in the custom post type learn more about Labels in WordPress

The $args are the arguments / options to go with the register_post_type function.

Step 3

Done, click save and refresh your wordpress site and you should have a custom post type in the dashboard section on the left-hand side. And if you go to http://yoursite.com/testimonials You’ll be greeted with the archive page for your custom post type.

Custom Post Type

Bonus

If you wanted a different design for your archive page for specific posts typePost from your cut from your post type is displayed or designed you can add additional files to your themeAs follows:

For a single post-it would be single-{posttype}.php e.g single-testimonial.php

And for a archive page it would be archive-{posttype}.php e.g archive-testimonial.php

If for some reason your archive page doesn’t show or your getting a white screen, here is a few things you can try.

  • Disabling your caching plugin
  • Goto Permalinks and click save a few times so that it refreshes the rewrites
  • Double check your code for any mistakes as thats usually the issue in some cases.

If your having an problems or issues let me know in the comments and I will gladly assist anyway I can.