My goal this week was to finish the main coding aspects for my site, which consisted of creating a custom post type (CPT) for “wine” as well as custom taxonomies for “region” and “year.” For every wine post I add, I’d like to associate the region and year of that wine. Last week, I attempted to create the CPT as a plugin and also in my functions.php file – both attempts failed (the CPT would show up on my local site, but not my real site).
This week, I took another shot at creating a CPT plugin and also adding custom taxonomies. After doing a little bit more research in the Codex and reading the Smashing Magazine CPT article, I finally got it to work by dragging the plugin file I created into Cyberduck! I initially tried to upload the zipped plugin file through the WordPress Admin, but I got an error message. I’m always quick to use the Admin, but in this case, dragging the file into Cyberduck was the only way it worked. I’m very happy to finally have my CPT and taxonomies showing up on my live site. As Ice Cube would say, today was a good day.
The reason for adding custom taxonomies was not only so I could sort my wine posts, but so visitors of my site could also have an easy way to sort through various posts. For example, if someone is only interested in wine from Napa Valley that was produced in 2008, they could choose those custom taxonomies and the site would generate all posts relating to those specifications. (This is assuming I had a variety of posts that met the criteria.) Simply creating a CPT/custom taxonomy plugin, however, wouldn’t automatically display the taxonomies in each post – this required more coding changes. Thanks to a little guidance from Greg, I determined that I needed to write a simple conditional statement in my content-footer.php file so that the custom tags (region and year) would be visible in each post. Another small victory when this actually worked for me!
My overall tip is to take the time to understand what and why you are changing something in the code. The possibilities of what to change in the code is endless, so it can be very overwhelming. For this project, I decided to concentrate on one major change (create a custom post type/custom taxonomies plugin) and try to understand everything there is to know about that plugin…what the code is actually doing, etc. I’m still no expert, but I hope that by having a good idea about what my first custom plugin is doing will help me make future coding changes – faster, easier and with less headaches.