Update on Movie Reviews Plugin

If you haven’t read my initial post on creating my first WordPress plugin, it will bring you up to speed.

I’m still working on this. One thing I’ve learned is that if I spend too much time away from the project, I forget where I left off. It’s a good thing I’m writing about it here.

Stupid $#&^(& Custom Field!

Because creating the plugin itself and incorporating a Custom Post Type was fairly easy to do, I started focusing on adding custom fields to the CPT to capture and store metadata. After reading a lot about how to create new tables and write to them, I struggled quite a bit with that in my plugin.

What’s weird about my struggle there is that I previously coded a whole site from scratch that accomplished that very thing. So why couldn’t I do it in WordPress? I sought some advice in a Post Status Slack channel, and the answer was simple: stop trying so hard to create a new table and just use the core WordPress post_meta table instead. Simple and brilliant.

I still haven’t tried that yet, because I wanted to do the more important work of creating a new post template for the reviews.

The Single Movie Template

Creating the template itself wasn’t hard. I just copied the single.php template and tweaked it. However, calling the template from the plugin was way more challenging. Apparently there are several ways to do it. I finally found a tutorial on it that worked… mostly. There were a lot of typos and some missing code that were frustrating to work through. However, I learned a ton about how it should work and I’m finally able to have a unique post template for the movie reviews. Right now it looks terrible.

screenshot of single movie template page

It may be obvious that I don’t have a style.css file for the post yet. Another issue is that the title of the post is missing. That “Single-movie template” header at the top is just an H1 tag I added to the template so I could make sure it was different from WordPress’s single.php template (no problem there, lol). So there’s that. Also, I need to create an archive template for the reviews — or figure out why it’s not defaulting to the WordPress archive template.

I still have a lot of work to do on this. But I’m learning. One thing I’m learning is that this would be much easier to do by creating a theme than a plugin. But I challenged myself to do this, and I’ll stick to it.

Except That This Will Soon Be History

It bears mentioning that while I’m working in WordPress 6.1, I’m using a non-block theme. The future of WordPress is no longer grounded in PHP, it’s more JavaScript. Also, there’s a way to do this using the Site Editor without writing much code at all — if I use a block theme, like Twenty-twenty-three.

So why bother solving these problems when what I should really be doing is learning better JavaScript and the new structure of WordPress?

I’ve thought about that a lot while banging my head on my keyboard. The thing is, I think it’s important for me to go through this process. I need to learn to solve these problems, even if the methods are deprecated. If I can’t follow through on this, then what will I do when I face a similar challenge in the “new” way? Part of this is about training myself to work through problems.

I’m going to keep at it, even if the plugin is never used.


Posted

in

, , ,

by

Tags:

Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.