Skip to content

Instantly share code, notes, and snippets.

@kaoru-fukusato
Created March 15, 2020 09:57
Show Gist options
  • Save kaoru-fukusato/a66d311ae8f7e1cbd3568b587ebd4bb0 to your computer and use it in GitHub Desktop.
Save kaoru-fukusato/a66d311ae8f7e1cbd3568b587ebd4bb0 to your computer and use it in GitHub Desktop.
記事ランダム②functions.php
//記事ランダム
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