WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Random redirect to a given category (1 post)

  1. mozey
    Member
    Posted 6 years ago #

    Hello guys, i recently needed to use random redirect, however ONLY to one category, edit your pluginfile, and set $random_id to this:

    $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_taxonomy_id = 1 ORDER BY RAND() LIMIT 1");

    replace the 1 that comes after term_taxonomy by your category id.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.