Software Engineering in WordPress, PHP, and Backend Development

Category: Notes (Page 14 of 49)

Notes on programming-related problems that I’ve encountered while working on various projects.

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

Viewing The PHP Debug Log

When building web applications, especially with PHP, there are some tools that are invaluable.

These include things like a good IDE, a powerful debugger, version control, and so on. But one of the things that I think we often neglect against our shiny tools are basic text files.

No, I don’t think we need to take a step back from our usual toolset, let’s not forget files also at our disposal.

Case in point: Let’s say you’re working on a web application. If you’re using PHP, then one way to do this is to view the PHP debug log.

It’s a simple text file that gives you as much information as you could want about any page in your project. Continue reading

Install PHP CodeSniffer with Composer

A little over a month ago, I talked about how to install the PHP Code Sniffer in an MAMP-based environment. Though you can read the post in its entirety, the short of is this:

  1. Setup Pear
  2. Install the package via Pear
  3. Grab the rules for the WordPress Coding Standards
  4. Begin evaluating your code

Easy enough, right?

But here’s the thing: As mentioned in the article, some may opt to use Composer to install the package. In fact, someone also mentioned this in the comments.

And since Composer is the default dependency management application for PHP projects, it makes sense to use it, right?

Composer

The funny thing is, since I’ve written that article, I’ve been using Composer in a few projects. So I thought it would make sense to show how to install PHP CodeSniffer with Composer.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑