Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 23 of 219)

Articles, tips, and resources for WordPress-based development.

Using Direct Database Queries to Quickly Update Data, Part 2

This is the second, and final part, in a series about – as the title suggests – direct database queries. Specifically, it’s about changing post statuses (but it’s relevant to more than that).

Photo by Ross Findon on Unsplash

From the previous post:

This is yet another post that’s going to be an illustration of how to use $wpdb to quickly update information based on metadata.

And the code provided in that post works but if you’re looking to make it more object-oriented, then there’s more work that can be done.

Before jumping into the actual post, though, it’s important to note that when it comes to object-oriented programming, there’s a lot of work that can go into the class design and creating levels of abstraction.

At some point, you have to draw the proverbial line between when you’re going to use interfaces, how granular your classes are going to be in terms of what they are abstracting, and the like.

And the purpose of this post is to help provide a better object-oriented design but it’s not an exercise is making this as optimal as possible. I do discuss topics like this in another series of posts.

But keep that in mind when reading through the code throughout the rest of the post.

Continue reading

Using Direct Database Queries to Quickly Update Data, Part 1

This is not the first time I’ve mentioned this, but one of the challenges that come with talking about writing direct database queries to update information in the WordPress database is that you leave yourself open to something like:

Yeah, but there’s an API to do something just like that.

And, in many cases, that’s right. I’m a big fan of using ’em, too. But there are times where direct, parameterized database queries can be a more optimal choice.

Direct Database Queries, Part 1

No, it’s not a database but wouldn’t it be awesome if they looked like this? Photo by Tobias Fischer on Unsplash

This is, of course, contingent on the environment in which you’re working the requirements of your project.

So this is yet another post that’s going to be an illustration of how to use $wpdb to quickly update information based on metadata (without using something like WP_Query or WP_Meta_Query to handle it).

Continue reading

WordCamp Atlanta 2019: Web Apps with WordPress

I’ve enjoyed speaking at WordCamps since my first back in 2013. You can see a short list of the ones at which I’ve spoken here:

And this weekend is officially WordCamp Atlanta 2019.

WordCamp Atlanta 2019: Web Apps with WordPress

I took 2018 off of speaking for several different reasons, and I’m not planning to do much in 2019 (especially with another kid making her debut later this year ❤️).

But given the work I’ve been doing with WordPress over the past few years, it seemed fitting to apply to at least speak at my local WordCamp.

Continue reading

Using Functions in Place of Globals: get_post_field

As PHP has continued to move forward and WordPress (and its developer-economy) works to begin using more of the more modern features, one of the things we still see happening is the use of globals within WordPress.

To some degree, it’s inevitable: Significant parts of the application were built using globals when that was the facility that was a primary feature; other parts, though, have moved forward by providing classes or functions that prevent us from needing to do that.

Case in point: get_post_field is a solid alternative to using the $post global that provides much of the same information in a slightly more modern (and arguably safer) way of reading the data.

Continue reading

How to Manipulate the DOM Using PHP

When it comes to manipulating the DOM, the first thing many of us likely think of is using JavaScript to do whatever it is we need to do.

Not only does the language natively support functions for doing this, newer features of ES6 give us more powerful ways to build client-side scripts. And if you’re using jQuery with WordPress, then you have the same library of functions for, ahem, querying the DOM that we’ve had for years.

But manipulating the DOM on the client-side isn’t always the best option. Instead, you may want to do so on the server-side. And because of some of the features built into PHP, it’s not much different from how we do things using JavaScript.

Manipulate the DOM Using PHP: Manipulate the DOM Using PHP: DOmDocument

Other than, of course, we’re doing so on the server.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑