In order to be able to use template tags, you have to do two things after getting your custom select query:
- You have to declare the
global $post
variable. - You have to call the setup_postdata($post) function to populate the variables.
So, my code had to be changed like so:
$results = $wpdb->get_results($wp_query->request, OBJECT);
global $post;
foreach ($results as $post) {
setup_postdata($post);
?>
<h4><a href="https://wordpress.stackexchange.com/questions/23088/<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
etc.
The key to this is on this codex page:
solved How to change a custom query into a standard loop?