Sorting the results | WordPress.org

Which add-on exactly are you using? I have so many it’s hard to tell which one you are referring to 😀

Plugin Name: Football Pool Sort Match Predictions

Yes, that is actually pretty easy. I can show you an example tonight. Basically boils down to adding an extra value to the $predictions array (e.g. 1 for the people with a prediction and 0 for those who didn’t). The logic for this is already in that add-on (as part of the remove inactive users). And with this value added to the array, you can use it in the sorting callback as a second sorting parameter for the spaceship operator (meaning when points are the same, then use this new value first to divide the players).

Hi @fanman1948 & @antoineh

can you please share location for Football Pool Sort Match Predictions ?

If this is in dropbox, is there a main download location with all plugins listed?

Thanx

@fanman1948 add the following line to your add_score function:

$prediction['user_has_prediction'] = ( is_null( $prediction['home_score'] ) || is_null( $prediction['away_score'] ) ) ? 0 : 1;

This will add a “1” to the array for people that have entered a prediction, and “0” for those who didn’t.

And then change the sorting rule in sort_table() to this:

return [$b['score'], $b['user_has_prediction'], $a['user_name']] <=> [$a['score'], $a['user_has_prediction'], $b['user_name']];

This should do the trick.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer