How to display projects in the portfolio with a random sequence

According to my knowledge, projects are ordered in the portfolio widget based on date and time of their insertion as projects.
Is there is a way to order them in a random sequence at every new load page or when the page get a new visit?
Furthermore, I saw that there is a way to display into the portfolio posts instead of projects (Configure the portfolio widget to display posts)
but even in that case, there is no mention of how to give a sequence order into the portfolio widget.
Thanks for your help.

Hello,

I don’t think that there is an easy way to get random sequence, but you can try to use Post Types Order plugin to reorder your projects:

Please feel free to ask any other questions that you might have.

Kind Regards, Roman.

Hello there,

In addition to what Roman have written, you could use use pre_get_posts hook to set custom query of a post type.

Add the below simple PHP code function to your child theme’s functions.php file. If do not want to run any child theme, you can also use a functionality plugin like Code Snippets. Ensure the snippet runs in the front-end.

/**
 * Enable random order of projects displayed in the widget
 */
add_action('pre_get_posts', 'sydney_child_change_projects_order', 9999);
function sydney_child_change_projects_order($query) {

  if( !is_admin() && !is_search() && !is_archive() && is_main_query() && $query->query_vars['post_type'] =='projects' ) {
    $query->set('orderby', 'rand'); // Random order
  }

}

Regards,
Kharis