How can I set the Query type to an ACF number or range field’s value? For example, if I had a star.png image, and I wanted to loop over it based on the page’s range value called “star_rating”, how would I go about that?
Did you manage this, im trying to set this up, same deal star rating on a testimonial
Cheers
Patric
Thanks. I ended up doing it myself with a little code block inside the loop which outputs full stars and empty stars dependent on the acf range value that is set (Called “rating” here).
<?php
$rating = intval(get_field('rating'));
for ($x = 1; $x <= 5; $x++) {
if ($rating>=$x){
echo '<i class="fullstar brxe-icon ion-ios-star"></i>';
} else{
echo '<i class="emptystar brxe-icon ion-ios-star-outline"></i>';
}
}
?>
Add a little css
.fullstar {
font-size: 25px;
color: #ffcc00;
fill: #ffcc00;
}
.emptystar {
font-size: 25px;
color: #ffcc00;
fill: #ffcc00;
}
.fullstar:before {
font-family: Ionicons;
content: "\f4b3";
}
.emptystar:before {
font-family: Ionicons;
content: "\f4b2";
}
And it works really well.
1 Like
Query editor (PHP) Query Loop – Bricks Academy
return [
'post_type' => 'post',
'posts_per_page' => '{acf_rating}',
];
Posts per page? How does that work as a star rating?
Nested loop within the main loop maybe?
Had to use
$rating = intval(get_field(‘rating’));
to get the rating value as {acf_rating} was not working but it does work, my code version though gives more scope for the hollow stars so I will stick with that.
1 Like