I am currently have a query written that grabs a random post from wordpress but excludes pages the person has previously been. $randomPost = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID NOT IN ($pageids) ORDER BY rand() LIMIT 1"); Code (markup): with out the php variables it looks like this: SELECT guid FROM hb_posts WHERE post_type = 'post' AND post_status = 'publish' AND ID NOT IN (1,13,5,29,23,33,17,3,35,20,0) ORDER BY rand() LIMIT 1 Code (markup): I have to take this query a little further. I need to have it exclude post but I also need it to only query from a certain category. The category will be a random category that I generate. I understand that I need to join but everything I've tried up to this point hasn't worked. Any help would be appreciated.