Link to random post in Category
-
Hello everyone, I currently have a button on my website that shows a random article when the users clicks on it. However I recently found out that some of the posts are from a category that I don’t want to be shown.
My question is, how do I alter this code so that it only shows posts from a certain category?
$randomPost = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY rand() LIMIT 1");
Thanks for the help!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Link to random post in Category’ is closed to new replies.