Clients, random order instead?

Hi!

I used the clients widget and I would love to make the client order to be random! I have over 25 clients and would like the order to change every time someone click on the displayed page, because it’s pretty “static” the way it is now. I can change the order with a plugin but I’m looking for more, this option doesn’t exist?

Thank you!

Hello there,

To accomplish it, you’re required to edit the core theme’s file which handles to clients widget setting and output. As editing theme’s file is actually prohibited because of theme update process overwrites all files of the theme, you should do file edit with a child theme.

Theme’s file for clients widget is widgets/fp-clients.php, to transfer it to child theme, follow the guide I’ve written in this thread. Ensure that you do widget class name adjustment as mentioned in these lines of code

    /*
     * Registering new widget
     */
    function sydney_child_register_new_widget(){
      register_widget( 'Sydney_Child_Employees' ); // Widget class name
    }
    add_action( 'widgets_init', 'sydney_child_register_new_widget' );

You do not need to add extra CSS code.

Then in replace this code block:

    $clients = new WP_Query( array(
    	'no_found_rows'       => true,
    	'post_status'         => 'publish',
    	'post_type' 		  => 'clients',
    	'posts_per_page'	  => $number,
    	'category_name'		  => $category,
    ) ); 

with:

    $clients = new WP_Query( array(
    	'no_found_rows'       => true,
    	'post_status'         => 'publish',
    	'post_type' 		  => 'clients',
    	'posts_per_page'	  => $number,
    	'category_name'		  => $category,
    	'orderby'  => 'rand'
    ) );

This line 'orderby' => 'rand' tells the query system to display clients randomly.

Regards,
Kharis

So helpful! I don’t regret asking then! Thank you so much :slight_smile:

You’re welcome!

Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

Regards,
Kharis