Skip Navigation

[Resolved] Continue/break a loop

This support ticket is created 5 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by triD 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1349465

Within a view, is there a method to "continue", as in skip this iteration, and go to the next iteration.

Is there also a "break" method as well? As in, stop this loop at the current iteration.

I cant seem to find any documentation on this, and it seems odd that these 2 methods wouldnt be available for loops.

Thanks.

#1349531

Hello, no there is nothing like a continue/break structure in Views loops. You can use conditional statements inside the loop, but they are evaluated after the query has been run. We also offer the PHP APIs wpv_filter_query and wpv_filter_query_post_process to perform other manipulation on the query itself with PHP.

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1349567

Thank you. Is there a reason why these 2 methods do not exist? It seems like an easy add to me. These 2 methods do not need to manipulate/change the existing query, it just needs to stop or skip the loop iteration.

#1349571

Offhand, no I'm not sure why they don't exist. I think most users are less knowledgeable of known code structures so they find other ways to solve problems. If you'd like to see continue and break added, I encourage you to submit your request in our forums over here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1349621

My issue is resolved now. Thank you!