Using Custom Post Meta to Retrieve WordPress Posts

The other day, I was in the process of setting up some custom post meta for an event post type. I needed to add a start date/time and an end date/time for the event as custom meta information. Once I got all of that set up, I needed to modify the loop so that it retrieved the events in order of their start date/time; but I also needed to make sure I only retrieved events that hadn’t yet ended (based on their end date/time).

In the past, this wasn’t really possible with WordPress. You could either order posts by a custom meta value, or you could limit your query to posts that had a specific custom meta value, but you couldn’t do both. Then, in version 3.1 of WordPress, the meta_query was introduced to the WP_Query class. Now, however, you can use the traditional orderby and meta_key properties to sort your posts by a specific meta value; and you can use the meta_query property to limit the posts that are returned.

Add a List of PDF Files to a WP Post

This evening, I found myself in the unique position of needing to display a list of PDF files at the bottom of a WordPress page. At first, I attempted to simply upload all of the PDF files using the WordPress image uploader, and then inserting a “gallery” at the foot of my post.

Unfortunately, I soon figured out that the “gallery” only displays images. In my case, that meant a blank space where I wanted the list of PDF files to appear (since, obviously, none of them are images).