Using Otto’s magic I didn’t test this but try it (it’s testing for category=4):
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 $numposts
Or:
http://ww.wp.xz.cn/support/topic/70359#post-444323
(which is the only thing I’m pointing out for random posts now…)
Thanks guys, this is awesome :o)
how do i put this code in the loop? i ve tried:
<?php // $the_query = new WP_Query('cat=-' .$catid. ',-' .$catid2. '&showposts=1&orderby=post_date&order=desc');
$the_query = "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 $numposts";
while ($the_query->have_posts()) : $the_query->the_post();
$do_not_duplicate = $post->ID; ?>
but it doesnet work.
Actually, you have to use query_posts with orderby=random and cat=
http://codex.ww.wp.xz.cn/Template_Tags/query_posts