WP - Random redirect
WP - Random redirect
Out of context: Reply #3
- 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.