wordpress wp_query orderby random
Use the code snippet below to randomly order the results of a WordPress query:
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
);
$query = new WP_Query( $args );
Explanation:
- post_type => 'post'
specifies that the query should retrieve posts.
- orderby => 'rand'
orders the posts randomly.
- WP_Query( $args )
creates a new WordPress query using the specified arguments.