Problems with the loop (looping within the loop) (1 post)

  1. Simon Ainley
    Posted 5 years ago #

    Hello I am working with my own template, and also using the post-to-post plugin, I am doing the following,

                    global $post;
                    global $related;
                    <?php query_posts('post_type=client'); ?>
                    <?php $the_query = new WP_Query( array('post_type' => 'casestudy', 'connected' => $post->ID)); ?>
                    <?php $content = $post->post_content; $link = $post->guid; $id = $post->ID; ?>
                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                        <?php $client = get_post_custom($post->ID); ?>
                            <img src="<?php echo $client['upload_image2'][0]; ?>" alt="<?php the_title(); ?>"/>
                        <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
                            <?php die("!"); ?>
                            <?php $related = get_post_custom($post->ID); ?>
                                <?php if(is_array($related)) : ?>
                                    <a href="<?php the_permalink(); ?>" class="case_study"><?php echo $content; ?></a>
                                <?php endif; ?>
                        <?php endwhile; ?>
                    <?php endwhile; endif; ?>
                    <?php wp_reset_postdata(); ?>

    However, I do not get into the second while, even though if I print_r $query_post it returns data. However If I then repeat the code again, it all works as I would expect, i.e the code goes into the second while loop, can anyone tell me why this would be happening?

Topic Closed

This topic has been closed to new replies.

About this Topic