Software Engineering in WordPress, PHP, and Backend Development

Category: Notes (Page 23 of 49)

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

Programmatically Add Post Terms in WordPress

Importing CSV files (or something similar) is something that’s nothing new to web development.

If you’re writing a server-side code that’s responsible for importing a file in the context of WordPress, then you can be doing anything from programmatically creating posts to creating more complex relationships among post types, taxonomies, and so on.

In this case, it’s nice to have an abstract function that can help to do a lot of the repetitive work for you. After all, aren’t functions specifically for that?

Continue reading

Adding Plugin Config Files to WordPress

Almost everyone who has worked with WordPress has dealt with wp-config.php. I know – there are a lot of managed hosts out there that take care of a lot of this for you – but even though a person may not have directly edited the file, they have definitely interacted with it.

For those who are unfamiliar:

This file is located in the root of your WordPress file directory and contains your website’s base configuration details, such as database connection information.

Anyway, for sometime now, I’ve been working on a relatively large plugin for a client and have recently taken to introducing a similar type of configuration files. So this raised that question, do what you think of plugin config files?

Continue reading

Tips for Saving and Retrieving Post Meta Data

One of the common things that I’ve seen – and personally done – is mismanaging $_POST data as it comes into the server-side from a form or some type of input element from the front-end. This may be in the case of sending data via Ajax or by doing a standard page refresh.

Chill Out, Veruca. We're getting there.

Chill Out, Veruca. We’re getting there.

Whatever the case, whenever you’re dealing with $_POST data in WordPress and you’re looking to save information into the database, there may be times where you’re interested in saving empty values, and there maybe times where you’re interested in savings values only if they are not empty.

If you’re going after the latter, there are a couple of safe guards you should introduce in your code to make sure that rows are only being written when there’s data to actually be written.

Continue reading

Single Page Tabbed Navigation in WordPress

In a couple of recent projects, I’ve been tasked with adding tabbed navigation to various WordPress templates. The thing is, these tabs work in such a way that all of the information is loaded on the page so when the user clicks on the tab, the contents of the page appear without having to do a page refresh.

Tabbed Navigation

 

In some cases, it may be best to load pages via Ajax, in some cases, it’s better to load things up all in the first page load. This particular post is about the best strategies for that (that’s a debate for another post).

Continue reading

Why You Should Write Meaningful WordPress Meta Keys

If you’re someone who’s building solutions with WordPress regardless of if they are themes, plugins, or applications, then odds are you’ve had to deal with saving some type of information to the database.

Granted, anytime you create a post, a page, or anything that stores data, you’re entering information into the database.

But that’s not what I’m talking about.

Instead, I’m talking about times when you’re having to work with the Options API, the Theme Customizer API, or one of the meta APIs (like the Post Meta API). In this case, you’re working with the core application to save and retrieve information from the database.

When doing this – especially in development and possibly in staging – it’s likely that you’re having to write the code, run a test (automated or not), and then take a look at the way the record is stored in the database to make sure it saved as expected.

In my experience, there are a handful of things that can be done to make this process a little bit easier and make your code a little bit cleaner and one of these has to do with writing meaningful WordPress Meta Keys

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑