samedi 5 décembre 2020

Insert a random variable into WordPress post

I want to insert a random variable into a WordPress post. To be more specific, the user who completes the test gets their score, i.e "You've got 10 out of 10" and I want to insert a text saying "Your score is better than 90% of the users who completed the test". But each time I want the percentage to be different in the range that I choose, for example, 85-100%. So each time someone completes the test, the text would display a variable with a percentage from 85% to 100%. Is this possible?

I'm using a WordPress plugin that is not updated anymore and I'd like to add some extra functions to it. At this point, it only lets me insert a text depending on how many correct answers the user had.

$percents = (int) round((($correctanswers/$attemptstoanswers) * 100), 0);
if ($percents > 0 && $percnets <= 33)
else if ($percents > 33 && $percents <= 67)
else if ($percents > 67 && $percents <= 100) 

I have of course searched before posting this question. But the only result I found was inserting a defined variable via functions.php and shortcode. I don't want a defined variable, I want it to be random from a specified range.

Thanks.

Aucun commentaire:

Enregistrer un commentaire