title: Loop in php the posts and add a class to polygon (leaflet)
body: <p>I am using Wordpress, I am looping my articles and for each article I am creating a case and adding a class. The case name and the class name are taken from custom fields attached to each post.</p>
  
  <p>However what happens is that if I have 2 articles related to a country e.g. Australia, the loop will say "found an article for Australia with this class, set a case and add its class". However, if i have 2 articles related to Australia, the case is already created for it therefore I won't be able to add a second class as it will skip it. Therefore I think I am doing it wrong and I shouldn't use <code>switch case</code>.</p>
  
  <p>The idea is to check for matches between the <code>country custom field</code> and the <code>sovereignt property within the geoson</code>, so that I can draw the country polygons if any article is related to a country, yet if I have 2 articles related to one country, the polygon is only drew once but there is the class issue as per above.</p>
  
  <pre><code>geojson = L.geoJson(statesData, {
      style: style,
      style: function(feature) {
          &lt;?php
            query_posts(array(
              'post_type' =&gt; 'post',
              'showposts' =&gt; -1
            ));
          ?&gt;
          switch (feature.properties.sovereignt) {
              &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
                  case '&lt;?php the_field("country"); ?&gt;': return {className: '_&lt;?php the_field("year"); ?&gt;'};
              &lt;?php endwhile; endif;?&gt;
          }
      },
      onEachFeature: onEachFeature
  }).addTo(map);
  </code></pre>
  
  <p>The switch case example i got it from <a href="http://leafletjs.com/examples/geojson/" rel="nofollow noreferrer">leaflet docs</a></p>