Display random post by cat name
-
Hi,
I’m use this query I found on here on the WP forums.
<?php
global $wpdb;
$numposts = 1;
$rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->post2cat,$wpdb->posts,$wpdb->categories WHERE
$wpdb->post2cat.post_id = $wpdb->posts.ID and $wpdb->post2cat.category_id = $wpdb->categories.cat_ID and $wpdb->posts.post_status = 'publish' and $wpdb->categories.cat_name = 'Designers we ♥' ORDER BY RAND() LIMIT $numposts");
foreach($rand_posts as $post):
setup_postdata($post);
?>
It’s worked very well for me but I’m in the process of upgrading my theme to WP 2.5 and this is now the only thing broken. I know there have been changes to the WP Database Schema and I’ve tried to decipher it, with no luck at all. Can anyone help with this, or see something similar I can then work from.
Thanks…
The topic ‘Display random post by cat name’ is closed to new replies.