DEV Community

Cover image for Wordpress concepts: Post types, The most basic things
Amirition
Amirition

Posted on • Updated on

Wordpress concepts: Post types, The most basic things

Wordpress came out as blogging platform at the early days. It means that the most basic thing that you can do with the Wordpress is to publish posts. As you may know as a developer, these posts store in the database. They have title, content, some tags, a featured image and all of this stores in the wp_posts of the database. (However, the wp prefix could be something else)
If you look at this table in the database, some of the notable columns are:

  • ID: Which is the primary key of this table and the main thing for you to identify a post.
  • post_author: Is the ID of the user that created this post(or assigned to be the author of this post)
  • post_title
  • post_content
  • post_name: This field is different with title, it's actually the slug of the title
  • post_type: This is the field that define the post type and create a separate menu for each post type in the amdin.

The posts are the standard post type in Wordpress. Pages and Attachments for example, are custom post types too. You can read more about Wordpress default custom post types at this link.

When and How?

CPT is an easy to understand concept. The more important thing is how to use it and when? Maybe it's better to tell you some cases that you can use CPT:

  • You want to create some content with the same functionality as posts, but not posts: This can be portfolio, movie, receipt, testimonial, etc.
  • Your content is not very similar to posts, but it's not that big or individual to create another table for it.

Well, to give you an idea to how to create a CPT, first of all, you must know when you should run your code, this is known as action filters. So as you can see in the examples of the WordPress developer documentation, you can run this code in the init action.
The full list of parameters are there and if you're developing a theme, you can put the code inside the functions file.

Latest comments (0)