Wordpress: Random posts & Pagination

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The Dawg
    Confirmed User
    • Apr 2002
    • 2438

    #1

    Wordpress: Random posts & Pagination

    I noticed if I order the post by random that Wordpress does not remember the posts displayed and repeats entries on the 2nd, 3rd, etc pages.

    Whats the best solution to shuffle the posts in a category, but make sure that they dont repeat?

    Thanks
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55679

    #2
    maybe something along these lines

    Code:
    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;
    }
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

    Comment

    • fris
      Too lazy to set a custom title
      • Aug 2002
      • 55679

      #3
      also have a look at this http://wordpress.mcdspot.com/2011/12...-set-of-posts/
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      Comment

      • The Dawg
        Confirmed User
        • Apr 2002
        • 2438

        #4
        Originally posted by fris
        maybe something along these lines

        Code:
        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;
        }
        I found this post also.

        I added it to the functions file and it works - but, it affects everything including the listings in the admin area.

        Originally posted by fris
        Where would I stick this code?
        Last edited by The Dawg; 08-08-2012, 07:49 AM.

        Comment

        • fris
          Too lazy to set a custom title
          • Aug 2002
          • 55679

          #5
          Originally posted by The Dawg
          I found this post also.

          I added it to the functions file and it works - but, it affects everything including the listings in the admin area.



          Where would I stick this code?
          you could check for is_admin() and whatever else, would need to know where you are putting the random bit, so you can only show it there.
          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

          Comment

          • CurrentlySober
            Too lazy to wipe my ass
            • Aug 2002
            • 38944

            #6
            Originally posted by The Dawg
            Where would I stick this code?
            So, so, so... Tempting


            👁️ 👍️ 💩

            Comment

            • V_RocKs
              Damn Right I Kiss Ass!
              • Nov 2003
              • 32449

              #7
              Get picks if you stick it up your ass

              Comment

              Working...