Sources:
- https://help.elegantthemes.com/en/articles/3068176-how-to-change-the-order-of-the-divi-portfolio-items
- https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
By default, the project order is by published date reversed order. Copy this code in the functions.php file of a child theme to change to random order:
// START order projects randomly
// Source: https://help.elegantthemes.com/en/articles/3068176-how-to-change-the-order-of-the-divi-portfolio-items
// Source: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
add_action( 'parse_query', function( $vars ) {
if ( isset($vars->query['post_type']) ) {
if ( 'project' == $vars->query['post_type'] ) {
$vars->set( 'orderby', 'rand' );
$vars->set( 'order', 'ASC' );
}
}
});
// END show projects in random orderCode language: PHP (php)