Two embarrassing things I did not get about WP-CLI at first

First things first

So in a previous entry I said: “I don’t know how the Austin WordPress Meetup folks knew that WP-CLI wants the post_name field to be referred to as pagename, but mad props to those folks for helping me out today.”

Well, the clue was there, I just didn’t catch it. The WP-CLI doc for wp post list says that one of the flags is for “One or more args to pass to WP_Query”.


I knew that WP-CLI was a way to interface with WordPress, but I “knew” it in a sort of cloudy, abstract way. When I finally realized I needed to look at the Codex page for WP_Query to understand wp post list, it crystallized in my mind that WP-CLI is calling the WP API.

I mean, of course it is, but it was a forehead-smacking moment for me when I finally got it.

In turn, I’ve realized even more clearly that I am coming at this “becoming a WordPress developer” thing kind of bass-ackwards, at least compared to how most people probably approach it.

So far, I’ve barely interacted with the WordPress API – except now via WP-CLI. Most of my direct work with WP has been in understanding how to set it up so that we can easily (or at least feasibly) move code and content between instances. I have done a scant bit of work in an Underscores theme but haven’t needed to add any functionality in the theme that wasn’t already there. I’ve had no occasion to write a plugin.

Out in the “WordPress world” (e.g. Twitter, blogs, online courses and tutorials) it’s easy to get the impression that being a WordPress developer equals writing plugins and themes and maybe setting up some custom post types or…  etc.

In fact, being a WordPress developer – today, before the REST API realizes its promise – means writing PHP code that interacts with the WP API. It may take the form of a plugin or a theme or something else but pretty much if you’re a WordPress dev, you need to know the API. But of course, people never say “HEY I TOTALLY CALLED SOMETHING IN THE API TODAY”. It’s more like “HAY I WROTE A PLUGIN THAT SOLVES THIS PROBLEM”. That’s legit, of course, but since it’s not like we all go to WordPress School and have an instructor that starts WP DEV 101 with the definition of a WordPress dev, it can be hard to pierce that veil and really understand what it is that a WP dev needs to know.

The second thing

I feel the need to correct something dumb that I did in that previous entry. I should also go back and correct it in that entry but for the moment I will just list it under things I didn’t understand.

So the dumb thing I did was use a SQL INSERT to add a post. Yeah, don’t do that. The wp post create command exists for Reasons.

When I really looked at the post I’d created with the SQL INSERT I realized that it had a lot of bad stuff that I’d forced into it. I was smart enough to let the database create the ID, but that was about the extent of my smarts. Dates that had no bearing on reality and a URL from another site polluted the post. The create command wasn’t all that long in the end. It was entirely manageable to write the command to do it properly.

TIL, I guess.