Est. reading time: 1 minutes
Quick Answer: THE REAL WP RAND FUNCTION CODE
//Modify the default WP query
function wp_custom_query( $query ) {
// Make sure we only modify the main query
if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
// Set parameters to modify the query
$query->set( 'orderby', 'rand' );
$query->set( 'order', 'DESC' );
$query->set( 'suppress_filters', 'true' );
}
}
// Hook our custom query to the pre_get_posts
add_action( 'pre_get_posts', 'wp_custom_query' );
And this wp function code really works :).
THE REAL WP RAND FUNCTION CODE
//Modify the default WP query
function wp_custom_query( $query ) {
// Make sure we only modify the main query
if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
// Set parameters to modify the query
$query->set( 'orderby', 'rand' );
$query->set( 'order', 'DESC' );
$query->set( 'suppress_filters', 'true' );
}
}
// Hook our custom query to the pre_get_posts
add_action( 'pre_get_posts', 'wp_custom_query' );