[Resolved] Conditional on amount of repeatable fields
This thread is resolved. Here is a description of the problem and solution.
Problem:
Conditional on amount of repeatable fields
Solution:
There is no native way to count the repeating field's number of instances, you need to write a custom shortcode to get the repeating field instance count.
We have a repeating date field which we'd like to use a conditional to show different content if there is more than 1 repeating field saved to the current post. Can you help, or point me to where I can see the conditional options for repeating fields?
Hello. Thank you for contacting the Toolset support.
Do you mean that you want to count the total repeating field entries and based on that total count you want to display some conditional content for the current post?
For instance, post X has 5 repeating date field entries and post Y has only 1, then you want to display something conditionally on post X. Where exactly you want to display conditional thing with your single post template?
That's right, I have a view for the repeating fields, which is rendered on the current post page. We just want to present the first date, with text after for any thing with >1 repeating fields.
Thanks, however, we wanted to render conditional text if there is greater than 1 repeating field.
[types field='departure-dates' style='text' format='j M, Y' index="0" item='$current_page'][/types]
This is fine to display the first field.
Then if more than 1 repeating field '...more dates available'.
Not the actual field data, is there a conditional to count the number of repeating fields?
2)
display the count result with above shortcodes, like this:
[count_rf_entries field="departure-dates"]
3)
You can display the conditional content using [wpv-conditional] shortcode:
Before using a custom shortcode inside a conditional, you need to register it. To do so, visit the Toolset -> Settings page and click the Front-end Content tab. There, simply add your shortcode to the Third-party shortcode arguments section.
For example;
[wpv-conditional if="( '[count_rf_entries field='departure-dates']' gt '1' )"]
your conditional content goes here
[/wpv-conditional]