Category Page Random post order with correct pagination
-
Hi – I have been working on a site that needs the category pages to randomize with correct pagination. I altered some code I found on the web. It worked when I put in 2 categories – but when I added them all in – it is no longer working. What did I miss? Should I use the slug instead? I am on new meds right now so I must have missed something….
add_filter( 'posts_orderby', 'randomise_with_pagination' ); function randomise_with_pagination( $orderby ) { if( is_category( 'Alabama, Arizona, Alaska, Arkansas, California, Colorado, Connecticut, Delaware, Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New Hamshire, New Jersey, New Mexico, New York, North Carolina, North Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode Island, South Carolina, South Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, Washington DC, West Virginia, Wisconsin, Wyoming' ) ) { // Reset seed on load of initial archive page if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) { if( isset( $_SESSION['seed'] ) ) { unset( $_SESSION['seed'] ); } } // Get seed from session variable if it exists $seed = false; if( isset( $_SESSION['seed'] ) ) { $seed = $_SESSION['seed']; } // Set new seed if none exists if ( ! $seed ) { $seed = rand(); $_SESSION['seed'] = $seed; } // Update ORDER BY clause to use seed $orderby = 'RAND(' . $seed . ')'; } return $orderby; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Category Page Random post order with correct pagination’ is closed to new replies.