Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 115 of 219)

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

Modifying the WHERE Clause in WordPress

When retrieving data, there times where you may want to change the WHERE clause in WordPress. That is, depending on what you’re retrieving, you may want to filter what it’s searching.

Using WHERE in WordPress to filter results

A favorite, but It’s not that kind of filter.

And that’s exactly what a WHERE clause does. But just as we’ve looked at content in other posts, we can alter the WHERE clause via the WordPress API.

In previous posts, I’ve covered:

Here, I’ll show how to use the API to change the WHERE clause so you’re not having to do so through a custom query.

Continue reading

Escaping Data in WordPress (And Why It’s Important)

You can read plenty of information about the importance of escaping information in WordPress via the Codex. If you’re new to the topic, I highly recommend it.

If you need a refresher, or are looking for a short description for why this is necessary, consider this the working definition:

For security on the other end of the spectrum, we have escaping. To escape is to take the data you may already have and help secure it prior to rendering it for the end user.

Clear enough, right? And WordPress offers plenty of functions to help with this.

How do we know which one to use, though?

Continue reading

JOIN Two Tables in WordPress

In a previous posts, I’ve talked about how to:

There’s a lot more to do than just viewing the last query and selecting distinct rows, though. For example, you can also JOIN two tables in WordPress without having to write raw SQL.

So to be consistent with some of the previous posts, I thought I’d share how to do this using the WordPress API .

Continue reading

Selecting DISTINCT Records in WordPress

If you need to write a query against the WordPress database, grab a reference to $wpdb and get to work, right?

In some instances, sure. I’m not opposed to this. After all, the API exists for a reason. But sometimes, I think we bypass built-in APIs. We go straight for $wpdb without looking to see if other hooks already exist.

Distinct

If a hook exists, why not use it? It’s one level of abstraction above the database and it uses the native API.

As mentioned in a previous post, I want to cover a few ways to customize queries that run against the database.

Case in point: selecting DISTINCT records from WordPress. Continue reading

How To Display The Last WordPress Query

Have you ever had the, ahem, pleasure of customizing the WordPress query? One of the most useful things in debugging is displaying the last WordPress query.

Let’s say you’re working with taxonomies and/or post types and you’re passing custom parameters around. And then, you want to setup some debugging to see exactly what’s hitting the database.

This is helpful for a variety of reasons if for no other reason than to see what is running against the database. It gives you insight on what you’re requesting and thus what you’re presenting to the user.

Anyway, writing code to do this is easy.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑