您好,我正在使用我自己的模板,并使用post-to-post插件,我正在执行以下操作,
<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>
然而,我没有进入第二个while,即使我打印r$query\\u post,它也会返回数据。然而,如果我再次重复代码,它就会像我预期的那样工作,即代码进入第二个while循环,有人能告诉我为什么会发生这种情况吗?
最合适的回答,由SO网友:mikkelbreum 整理而成
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);