Created
March 15, 2020 09:57
-
-
Save kaoru-fukusato/a66d311ae8f7e1cbd3568b587ebd4bb0 to your computer and use it in GitHub Desktop.
記事ランダム②functions.php
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
//記事ランダム | |
session_start(); | |
add_filter('posts_orderby', 'edit_posts_orderby'); | |
function edit_posts_orderby($orderby_statement) { | |
$seed = $_SESSION['seed']; | |
if (empty($seed)) { | |
$seed = rand(); | |
$_SESSION['seed'] = $seed; | |
} | |
$orderby_statement = 'RAND('.$seed.')'; | |
return $orderby_statement; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment