Welcome to a series of tutorials on how register, customize, and use WordPress custom post types! One of the things that beginning WordPress developers seem to always forget about is that sometimes a website requires more than just posts and pages to input data. When you are deciding on how your back end UI should look, you should consider how the information is going to be used and if you want to pull that information in to various spots across your website.
Example Use Case:
For this tutorial series we are going to make a custom post type for testimonials. Most companies want to have a few blurbs written by past or current customers that talks about how great their products or services are. What if your client has a few different products or services that they want to highlight with testimonials? Wouldn’t it be great if you could pull in a featured testimonial on that service’s detail page?
Let’s assume this is for a creative agency. They do logo design, website design, and marketing and they have testimonials from clients who have used all or one of their services.
Planning your information architecture
I say this in all my tutorials, but this is the stage that most new developers completely skip and it not only drives me insane, but it really comes back to bite them in the butt further down the road. When your information that is entered in to your custom post type form isn’t planned properly you will run in to all sorts of problems. For instance, you might find that you not only wanted to display testimonials as they relate to their respective services, but your website also has users and you wanted to align their testimonial with their perspective user profile. If you did not plan this ahead of time you would have to go back and replace all of the basic text inputs for “name” with a user ID and rewrite your front end code accordingly. But, since this really is a basic tutorial, we aren’t going to do that, it’s just some food for thought. Think about all scenarios possible in how you are going to use your information on the front end and how you might want to categorize, tag, and organize the information you are going to enter.
For this tutorial we are going to have a few inputs that are default WordPress post inputs and a few custom fields and meta boxes. We are definitely going to need a name (basic text input) and testimonial field (text area with WYSIWYG). Since those two fields pretty much exist in a normal WordPress post UI via the post_title() and the_content() we are set there. Then we want to have a checkbox so that we can set it as a featured testimonial. This will allow us to float these featured testimonials to the top of any of our list or filter out all non-featured testimonials from certain pages. We will also want a way to associate a photo or video to this testimonial. WordPress comes with the awesome Featured Image, so we can use that for our photo, and for our video we will use a text input where the administrator can simply paste in the URL to the video (most of my clients prefer to upload their videos to YouTube or Vimeo to not only give them more exposure but to also not have to deal with the load of streaming video content).
We are building a testimonial custom post type with the following fields:
- Testimonial Content
- Featured (yes/no)
- Featured Image
- Video link
Wait, what? NO CODE!!! I feel scammed!
Don’t. If you took the time to read this instead of just skipping to the parts with the code to simply paste into your theme you will be better for it . I promise.