‘for-each’ with ‘exists’
-
I am trying to build a shortcode to display several categories of academic degrees within a for-each loop of academic departments.
The basic structure is:
[for each=department]
[each name]
CONDITIONAL HEADER
[loop type=academics taxonomy=division term={TERM} taxonomy_2=degree term_2=ug compare_2=and list=true][field title-link][/loop]
CONDITIONAL HEADER
[loop type=academics taxonomy=division term={TERM} taxonomy_2=degree term_2=grad compare_2=and list=true][field title-link][/loop]
[/for]In some departments, one of the loops will be empty. Because of that, the header needs to display only if there are posts in the loop. I found two ways (below) to make the header display only when there are posts in the loop, but both of them break any ‘for-each’ statements below them on the page.
– This works to make the header conditional but breaks any following for-each:
[if exists type=academics taxonomy=division term={TERM} taxonomy_2=degree term_2=ug compare_2=and]<h6>Undergraduate Majors</h6>[/if]
– This works to make the header conditional but also breaks any following for-each:
[loop exists type=academics taxonomy=division term={TERM} taxonomy_2=degree term_2=ug compare_2=and list=true]<h6>Undergraduate Majors</h6>
[the-loop][field title-link][/the-loop]
[/loop]
– This DOES NOT break anything following and does not display the header if the loop is empty, but (as it should) it loops through and writes the header once for each post, so if there are 4 posts in the list it writes the header 4 times:
[loop type=academics taxonomy=division term={TERM}][if taxonomy=degree term=ug]<h6>Undergraduate Majors</h6>[/if][/loop]It seems like the conflict comes from ‘exists’, and ‘exists’ doesn’t break the for-each it’s in but breaks any for-each that follows. Is this a bug, or is my syntax wrong?
Thx, Susan
- The topic ‘‘for-each’ with ‘exists’’ is closed to new replies.