admin管理员组文章数量:1317572
I'm not able to figure out the solution for the following code. When I remove the query section, the location loops but with the code, only one result of location (parent loop) is displayed.
if (have_rows("locations")):
while (have_rows('locations')): the_row();
?>
<section class="content container pt-0">
<div class="contain-container">
<div class="row">
<div class="col-xs-12 col-lg-12" data-aos="fade-up">
<?php
<div class="displayaddress">
<div class="col-lg-6 col-sm-12">
<div class="p-lg max-conten">
<?php echo get_sub_field("content_text"); ?> </div>
<?php
$link = get_sub_field('content_button_link');
if ($link) {
$link_url = get_sub_field('content_button_link');
} else {
$link_url = "#";
}?>
<div class="info">
<p class="st3">Address</p>
<p class="p-md"><?php echo get_sub_field('address'); ?></p>
<a href="<?php $link_url;?>" class="gold-link grey">GET DIRECTIONS →</a>
</div>
<div class="info">
<p class="st3">Phone</p>
<p class="p-lg"><?php echo get_sub_field('phone'); ?></p>
</div>
<div class="info">
<p class="st3">Opening Hours</p>
<p class="p-lg"><?php echo get_sub_field('opening_hours'); ?></p>
</div>
</div>
<div class="col-lg-6 text-right col-sm-12">
<?php echo get_sub_field('map_iframe'); ?>
</div>
</div>
<?php $featured_posts = get_sub_field('designs_on_display');
if ($featured_posts) {
?>
<p class="mid-gold st2 bold container dod-title">Designs on Display</p>
<div class="designondisplay">
<?php foreach ($featured_posts as $featured_post) {
$args = array(
'p' => $featured_post,
'post_type' => 'any',
'post_parent' => 0,
);
$query = new WP_Query($args);
while ($query->have_posts()): $query->the_post();
$termsBath = get_the_terms($post->ID, 'bathrooms');
$termsBath = array_shift($termsBath);
$storey = get_the_terms($post->ID, 'storeys');
$storey = array_shift($storey);
$bedroom = get_the_terms($post->ID, 'bedrooms');
$bedroom = array_shift($bedroom);
?>
<div class="col-sm-12 col-md-6 col-lg-3 p-0" data-aos="fade-up">
<div class="project-grid ">
<a href=" <?php echo get_permalink(); ?>">
<?php
while (have_rows('home_images')): the_row();?>
<?php
$image = $image_url[0];?>
<img src="<?php echo get_sub_field('image')['url'] ?>"
alt="<?php echo get_the_title(); ?>" />
<?php
break;
endwhile;
?>
<div class="projectMeta">
<div class="projectIcons">
<h5 class="p-lg gold-9b"><?php echo get_the_title(); ?>
</h5>
<?php
$bedroom = $bedroom->name;
echo '<span class="icon-number"><img class="bedIcon" src="' . get_template_directory_uri() . '/images/[email protected]" />';
echo str_replace("Bedrooms", "", $bedroom) . '</span>';
if (!empty($termsBath)) {?><span class="icon-number"><?php
echo '<img class="bathIcon" src="' . get_template_directory_uri() . '/images/[email protected]" />';
$bathroom = $termsBath->name;
echo str_replace("Bathroom", "", str_replace("Bathrooms", "", $bathroom));
echo "</span>";
}
?>
</div>
</div>
</a>
</div>
</div>
<?php endwhile;}
}
?>
</div>
</div>
</div>
</div>
</section>
<?php
endwhile;
endif;
?>
I'm not able to figure out the solution for the following code. When I remove the query section, the location loops but with the code, only one result of location (parent loop) is displayed.
if (have_rows("locations")):
while (have_rows('locations')): the_row();
?>
<section class="content container pt-0">
<div class="contain-container">
<div class="row">
<div class="col-xs-12 col-lg-12" data-aos="fade-up">
<?php
<div class="displayaddress">
<div class="col-lg-6 col-sm-12">
<div class="p-lg max-conten">
<?php echo get_sub_field("content_text"); ?> </div>
<?php
$link = get_sub_field('content_button_link');
if ($link) {
$link_url = get_sub_field('content_button_link');
} else {
$link_url = "#";
}?>
<div class="info">
<p class="st3">Address</p>
<p class="p-md"><?php echo get_sub_field('address'); ?></p>
<a href="<?php $link_url;?>" class="gold-link grey">GET DIRECTIONS →</a>
</div>
<div class="info">
<p class="st3">Phone</p>
<p class="p-lg"><?php echo get_sub_field('phone'); ?></p>
</div>
<div class="info">
<p class="st3">Opening Hours</p>
<p class="p-lg"><?php echo get_sub_field('opening_hours'); ?></p>
</div>
</div>
<div class="col-lg-6 text-right col-sm-12">
<?php echo get_sub_field('map_iframe'); ?>
</div>
</div>
<?php $featured_posts = get_sub_field('designs_on_display');
if ($featured_posts) {
?>
<p class="mid-gold st2 bold container dod-title">Designs on Display</p>
<div class="designondisplay">
<?php foreach ($featured_posts as $featured_post) {
$args = array(
'p' => $featured_post,
'post_type' => 'any',
'post_parent' => 0,
);
$query = new WP_Query($args);
while ($query->have_posts()): $query->the_post();
$termsBath = get_the_terms($post->ID, 'bathrooms');
$termsBath = array_shift($termsBath);
$storey = get_the_terms($post->ID, 'storeys');
$storey = array_shift($storey);
$bedroom = get_the_terms($post->ID, 'bedrooms');
$bedroom = array_shift($bedroom);
?>
<div class="col-sm-12 col-md-6 col-lg-3 p-0" data-aos="fade-up">
<div class="project-grid ">
<a href=" <?php echo get_permalink(); ?>">
<?php
while (have_rows('home_images')): the_row();?>
<?php
$image = $image_url[0];?>
<img src="<?php echo get_sub_field('image')['url'] ?>"
alt="<?php echo get_the_title(); ?>" />
<?php
break;
endwhile;
?>
<div class="projectMeta">
<div class="projectIcons">
<h5 class="p-lg gold-9b"><?php echo get_the_title(); ?>
</h5>
<?php
$bedroom = $bedroom->name;
echo '<span class="icon-number"><img class="bedIcon" src="' . get_template_directory_uri() . '/images/[email protected]" />';
echo str_replace("Bedrooms", "", $bedroom) . '</span>';
if (!empty($termsBath)) {?><span class="icon-number"><?php
echo '<img class="bathIcon" src="' . get_template_directory_uri() . '/images/[email protected]" />';
$bathroom = $termsBath->name;
echo str_replace("Bathroom", "", str_replace("Bathrooms", "", $bathroom));
echo "</span>";
}
?>
</div>
</div>
</a>
</div>
</div>
<?php endwhile;}
}
?>
</div>
</div>
</div>
</div>
</section>
<?php
endwhile;
endif;
?>
Share
Improve this question
asked Nov 2, 2020 at 6:44
Miraj AryalMiraj Aryal
1
1 Answer
Reset to default 0After using the WP_Query
in a custom loop, you might need to reset the global query object. Try calling the wp_reset_query()
function after your while
loop.
https://developer.wordpress/reference/functions/wp_reset_query/
本文标签: wp queryWPQuery breaking the loop in a nested loop
版权声明:本文标题:wp query - WP_Query breaking the loop in a nested loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742020894a2414651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论