fahimmurshed

UAE Post Duplicate

Jul 13th, 2022 (edited)
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. //Use it in the functions.php file
  2. //Displaying duplicate posts is the expected behavior of the WordPress query, here we have managed it by applying the tweak.
  3.  
  4. function prefix_start_session() {
  5.     if( !session_id() ) {
  6.         session_start();
  7.     }
  8. }
  9. add_action( 'init', 'prefix_start_session' );
  10.  
  11. function get_random_post() {
  12.     if ( !isset( $_SESSION['random'] ) ) {
  13.         $_SESSION['random'] = rand();
  14.     }
  15.     return $_SESSION['random'];
  16. }
  17.  
  18. add_action('uael_posts_query_args', function($query){
  19.     $query['orderby'] = 'rand(' . get_random_post() . ')';
  20.     return $query;
  21. });
Add Comment
Please, Sign In to add comment