I have a job listing board on the site I'm building. There are jobs available in multiple states, and I'd like to have them listed by state with the state name at the top, but only if there are job posts for that state. If there are no jobs listed for a state, then don't show the state title.
The idea is to show a header that displays the state the jobs are available in, but show no header if there are no jobs in that state. For example, if I have jobs posted in Arizona and Nevada, but no jobs posted in California, I'd like to see:
ARIZONA
Job Title
Company
City, State, Zip
Job Title
Company
City, State, Zip
NEVADA
Job Title
Company
City, State, Zip
Job Title
Company
City, State, Zip
I've tried creating a conditional output based on a custom field called "state":
[wpv-conditional if="( $(wpcf-state) eq 'NV' )"]
<h3>Nevada</h3>
(My job listing content template shows title, company, city, state, zip as shown above)
[/wpv-conditional]
This works ok, but if I include the state at the top as shown, the state shows above every job, which is what I would expect because it's looping through the content template for each job that has Nevada listed as the state.
Is there a way to show the state at the top of the listings one time as shown above without having to create a separate view for each individual state? For example (pseudocode), "If there are posts where wpcf-state = NV, display <h3>Nevada</h3> at the top, then loop the posts where wpcf-state = NV below."