• umair

    (@umair)


    I want to use matt’s random redirect plugin …
    but not for posts, i want to use it for picture attachments of that post?

    Following is the if condition Matt is using, how can it be modified for attachment of a single post( which say have post id = 1)

    `if ( isset( $_GET[‘random_post_type’] ) ) {
    $post_type = preg_replace( ‘|[^a-z]|i’, ”, $_GET[‘random_post_type’] );
    $query = “SELECT ID FROM $wpdb->posts WHERE post_type = ‘$post_type’ AND post_password = ” AND post_status = ‘publish’ ORDER BY RAND() LIMIT 1″;
    }

    $random_id = $wpdb->get_var( $query );

    wp_redirect( get_permalink( $random_id ) );
    exit;`

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter umair

    (@umair)

    any one ?

    Thread Starter umair

    (@umair)

    hello……..

    wp_guy

    (@wp_guy)

    You can add this bit:

    if ( isset( $_GET['random_attachment'] ) ) {
    		$post_parent = $_GET['random_attachment'];
    		$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_parent' ORDER BY RAND() LIMIT 1";
    	}

    Then get it like this: yourblog.com/?random&random_attachment=1 (for post ID 1)

    Hope that helps

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Random Redirect for Attachments of a post.’ is closed to new replies.