Skip Navigation

[Resolved] Iterate a number of times

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#555490

Hello,

- I have a custom field with a numeric value, from 1 to 5
- I want to iterate that number of times and output stars within a Content Template

So for example if a post has a value of 3, I want to output <img src="star.gif"> three times.

Something like:

loop n + 1 until n = {custom field value}

This is the closest I have found after one hour searching: https://toolset.com/forums/topic/incremental-row-numbers-in-views/#post-31061 ... however this solution will loop for each post, whereas I actually need it to loop a set number of times, as determined by a custom field in each post.

Can you please advise?

Many thanks

#555528

Dear Hector,

I suggest you try with shortcode [wpv-conditional], like this,
check if the custom field value is 1, then display 1 star image
check if the custom field value is 2, then display 2 star images
check if the custom field value is 3, then display 3 star images
...
Since there are only 5 options, so it should be able to setup easily.
More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional
Conditional shortcode to be used to display a specific block of meta HTML based on results of a boolean expression

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.