Modifying the WHERE Clause in WordPress
read more
Categories

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.
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:

Displaying the last query, which is useful when doing light debugging.
Selecting DISTINCT records
Performing a JOIN on two tables

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.

Changing The WHERE Clause in WordPress
If you’re new to SQL or you need a refresher on the purpose of a WHERE clause, check out this definition:
The MySQL WHERE clause is used to filter the results from a SELECT, INSERT, UPDATE, or DELETE