Home › Forums › General Issues › Translate number (1-5) to stars on front end › Reply To: Translate number (1-5) to stars on front end
Found a snippet and modified it a little, seems to work now!
<?php
$starNumber = get_field('rating');
for($x=1;$x<=$starNumber;$x++) {
echo '<i class="fa fa-star" aria-hidden="true"></i>';
}
if (strpos($starNumber,'.')) {
echo '<i class="fa fa-star-half-o" aria-hidden="true"></i>';
$x++;
}
while ($x<=5) {
echo '<i class="fa fa-star-o" aria-hidden="true"></i>';
$x++;
}
?>
For anyone using this: it’s based on the stars from FontAwesome, with the smallest step being .5
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF’s Repeater field is a versatile solution for repeating content in #WordPress.
— Advanced Custom Fields (@wp_acf) December 29, 2022
What’s your favorite use case for the Repeater field?
What’s the weirdest thing you’ve ever used it for?
Let us know!👇
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.