Created
August 24, 2015 07:30
-
-
Save shizhua/97aaa25cde1fdee73460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Random Post | |
* | |
*/ | |
?> | |
<?php | |
$args = array( | |
'posts_per_page' => 1, | |
'orderby' => 'rand' | |
); | |
$my_random_post = new WP_Query ( $args ); | |
if ($my_random_post->have_posts()) : | |
while ($my_random_post->have_posts()) : $my_random_post->the_post(); ?> | |
<?php | |
wp_redirect ( get_permalink () ); | |
exit; | |
?> | |
<?php endwhile;?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment