Forked from nickkoskowski/gist:2fb00a84b2be7f91cb30
Last active
August 29, 2015 14:27
-
-
Save eminozlem/84c07a9834aed2062f63 to your computer and use it in GitHub Desktop.
Get a random post link from WP database using query
This file contains hidden or 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 | |
| function get_random_post_link() { | |
| $args = array( | |
| 'orderby' => 'rand', | |
| 'posts_per_page' => '1', | |
| ); | |
| $wp_query = new WP_Query( $args ); | |
| if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); | |
| $postlink = get_the_permalink(); | |
| endwhile; endif; wp_reset_query(); | |
| return $postlink; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment