Last active
August 29, 2015 13:57
-
-
Save michaeldozark/9839809 to your computer and use it in GitHub Desktop.
Edit SQL ORDER BY statement to randomly order posts after other orders are accounted for.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* slimline_random_orderby function | |
* | |
* Edit SQL ORDER BY statement to randomly order posts after other orders are accounted for. | |
* | |
* @param string $orderby The ORDER BY statement generated by get_posts() | |
* @return string $orderby ORDER BY statement with RAND() set as an additional clause | |
*/ | |
function slimline_random_orderby( $orderby ) { | |
// Append SQL RAND function to an existing orderby statement or return by itself if $orderby is empty | |
return ( $orderby ? ',' : '' ) . 'RAND()'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment