Magicfields foreach not stopping, iterating too many

Using the magicfields 2.0 plugin for WordPress 3.1.
Here’s the broken page:
http://sseko.wecreativeagency.com/style/

and here’s a page with it working:
http://sseko.wecreativeagency.com/university-bound/

Read More

Note the footer on the first page is receiving the id info from the magicfields

<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <article  id="post-<?php the_ID(); ?>">

            <?php the_content(); ?> 
            <div id="note" class="grid_12"><p class="note grid_6 alpha"><span class="special">Style your Ssekos!</span> There are so many ways to tie your Ssekos. Watch the videos and learn how! Then, come up with your own!</p><h1 class="grid_6 omega"><?php wp_title(' ','true','right'); ?></h1></div>                   
            <?php $styles = getFieldOrder('image'); 
                                if(is_array($styles))
                                {foreach($styles as $style)
                                    {
                                     echo "<div class='grid_3'>";
                                     echo "<a rel='styles' href='#info$style'class='inlineimg grid_3'>";
                                     echo "<img src='";
                                     echo get_image('image',1,$style,$tag_img=0);
                                     echo "'class='grid_3' title='";
                                     echo get('name',1,$style);
                                     echo "'alt='";
                                     echo get('name',1,$style);
                                     echo "'";                                       
                                     echo "</a>";
                                     echo "<h2 class='grid_3'>";
                                     echo get('name',1,$style);
                                     echo "</h2></div>";
                                     echo "<div style='display:none'><div id='info$style' class='grid_8 lightbox'>";
                                     echo get('link',1,$style);
                                     echo "</div></div>";

                                    }
                                }
                                ?>
    <div class="clear"></div>   
    </article>
    <?php endwhile; endif; ?>

I’ve check the database for extra entries but I can’t find the reason for it continuing to iterate out into the elements below.

Related posts

Leave a Reply

1 comment

  1. For some reason I could not check your site .. but I believe this is hapenning because you have 2 nested loops ..
    One is the WordPress loop if–> while , and then your Foreach loop.
    When the WordPress loop encounters posts , it will iterate your second loop FOR EACH ONE of the posts …
    for example, on a page where there are 10 $post, it will iterate 10 times for each $style …
    When you have 1 post , it will iterate once .
    Like I said, for some reason your site was not available to me , but seeing your URL construction, My guess is that it does not work on the first example, because it is some kind of category (which returns multiple posts ) and the second url is a SINGLE post …