Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

<ul>
                <?php
                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); ?>
                    <li>
                        <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; ?>
                    </li>
                <?php endwhile; endif; ?>
                <?php wp_reset_postdata(); ?>
            </ul>

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?

share|improve this question
    
Why do you have two loops inside of each other. You need to separate them. –  Pippin Jul 13 '11 at 16:27
    
I am looping within each other, as some of the posts have a related post in another content type so to do the check I need to loop within a loop. –  sico87 Jul 13 '11 at 16:32
add comment

1 Answer 1

up vote 1 down vote accepted

did you try this?

$custom_query_args = array(
    'post_type' => 'casestudy',
    'connected' => $post->ID
);

$the_query = new WP_Query();
$the_query->query($custom_query_args);
share|improve this answer
    
tried this, but it has made no difference –  sico87 Jul 13 '11 at 19:29
    
bit of re-jigging I got this to work, thanks! –  sico87 Jul 14 '11 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.