WP - Random redirect
- Started
- Last post
- 4 Responses
- Jaline0
function random_redirect() {global $wpdb;
$random_id = $wpdb->get_var( "SELECT wp_posts.ID FROM $wpdb->posts, wp_term_relationships WHERE wp_posts.post_type = 'post' AND wp_posts.post_password = '' AND wp_posts.post_status = 'publish' AND wp_posts.ID = wp_term_relationships.object_id AND wp_term_relationships.term_taxon... = 22 ORDER BY RAND() LIMIT 1");
wp_redirect( get_permalink( $random_id ) );
exit;
}I had issues with it first latching onto a tag and only cycling through those specific posts, and then, when I altered some of it, it changed to just redirecting to the newest post.
- Jaline0
Bump for the night crowd.
- ernexbcn0
Try this (75,76,77 are your category IDs):
query_posts('orderby=rand&showpo...
if (have_posts()) :
while (have_posts()) : the_post();....
- QBN ate the code:
http://pastie.org/16…ernexbcn - thanks, giving it a go nowJaline
- QBN ate the code:
- Jaline0
Maybe something like this:
<?php query_posts('showposts=1&cat=22,23,24,25&orderby=rand');?>
except in link format