One question I come across a lot regarding custom fields is how to only retrieve posts based on a custom field. For example, if a post has a custom field of “MyData”, someone might want to only retrieve that particular post. The WordPress Codex has a technique for retrieving posts based on custom fields, which consists of writing your own query and going through the results. The technique in the Codex is good, but I’ve found a re-usable way one can retrieve only posts with certain custom fields. The technique I use makes use of two custom functions placed in a theme’s “functions.php” and a custom WordPress Loop. Let’s get started — The “functions.php” file First, let’s place the two custom functions in the “functions.php” file. This file should be in your theme directory, but if it isn’t there, you can create one using any text editor. Here are the […]
[Continue Reading...]