Okay. Education time. Let’s look at your query.
SELECT * FROM $wpdb->posts AS p,
$wpdb->post2cat AS c
WHERE p.ID = c.post_id
AND c.category_id = 4
AND p.post_status = 'publish'
ORDER BY RAND()
LIMIT $num
This is getting random published posts from the category with a number of 4. Right? Now, you want to do something similar, I assume. Since random isn’t (yet) one of the built in selectors (I have submitted a patch though), we’ll need to do a query manually.
The old way:
wp_posts held posts.
wp_categories held categories.
wp_post2cat linked the two.
The new way:
wp_posts holds posts.
wp_terms holds “terms”, which are basically words.
wp_term_taxonomy holds the “taxonomy”, which gives these words meaning (like “tag” or “category”).
wp_term_relationships associates a term_taxonomy with some other object, like posts.
So, basically you want to do some joins.
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->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id = 4
ORDER BY RAND()
LIMIT $num
That assumes that the term numbered “4” is still the category number you’re interested in, it may have changed with the upgrade.
This is just off the cuff, BTW, there may be syntax errors there or something. ??