ACF Number field displayed as star rating

I have a loop of ‘review’ post types with an ACF number field for the star rating that I want to display as stars.

I can easily do this via php and create a shortcode but wondering if anyone has done it within L&L and wouldn’t mind sharing their code?

Also need to do an aggregate rating of all reviews with a taxonomy term. Anyone done this?

At a really basic level, you could this with a times loop. I imagine it could look something like this:

<Loop times="{Field rating_number_field}">

Or you could do what we did on the home page of the L&L site (the full template can be found by clicking the duck character next to the reviews on that page):

<Switch check="{Field acf_radio=rating}">
  <When value="5" />★★★★★
  <When value="4" />★★★★☆
  <When value="3" />★★★☆☆
  <When value="2" />★★☆☆☆
  <When value="1" />★☆☆☆☆

You’ll probably want to use the Math tag. Loop through all your results, add them up, then divide them by <Get loop=previous_total />

1 Like

Thank you! Very helpful.

(Love the duck btw :grinning:)

1 Like