for future reference… the function I’ve ended up using is as follows. I’ve called it get_tickets because I’m using this to display posts styled as trouble tickets (hence the relevance of the open/closed status):
function get_tickets($categories, $status='open', $limit=100) {
global $wpdb;
$sql = "SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships
ON($wpdb->posts.ID=$wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy
ON($wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->term_taxonomy.term_id='$categories'
AND $wpdb->term_taxonomy.taxonomy='category'
AND $wpdb->posts.post_status='publish'
AND $wpdb->posts.comment_status='$status'
ORDER BY $wpdb->posts.post_date DESC
LIMIT $limit;";
$results = $wpdb->get_results($sql);
if (!empty($results)) return $results;
else return FALSE;
}
to then display the results, you would:
<?php
$tickets = get_tickets($ticket_category_id, 'open');
if ($tickets) foreach ($tickets as $post) :
setup_postdata($post);
?>
[regular loop stuff goes here]
<?php endforeach; ?>
obviously, you can adapt this for your own needs.