Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Use it in the functions.php file
- //Displaying duplicate posts is the expected behavior of the WordPress query, here we have managed it by applying the tweak.
- function prefix_start_session() {
- if( !session_id() ) {
- session_start();
- }
- }
- add_action( 'init', 'prefix_start_session' );
- function get_random_post() {
- if ( !isset( $_SESSION['random'] ) ) {
- $_SESSION['random'] = rand();
- }
- return $_SESSION['random'];
- }
- add_action('uael_posts_query_args', function($query){
- $query['orderby'] = 'rand(' . get_random_post() . ')';
- return $query;
- });
Add Comment
Please, Sign In to add comment