Answer the question
In order to leave comments, you need to log in
Wordpress, why does the loop break if there are more than one post?
If there is only one post, then everything is ok. But if more, then some kind of gibberish, the page does not load further and the trouble turns out.
WP_Query object received, everything is ok. With all posts.
Here is the problem page. Tellingly, on other pages the cycle runs normally, but for some reason it doesn’t here.
THANK YOU SO MUCH for any help, because I've been suffering with a bug for a day
www.123.9co.ru/usability
<?php
/**
* Template Name: Grepta Usability (Cases)
*/
get_header(); ?>
<style>
.loader {
display: none;
}
</style>
<section id="case-section">
<div class="site-size">
<div class="section-heading">
<h2>Кейсы</h2>
</div>
<div class="case-slider-wrap">
<div id="case-slider">
<ul class="slides">
<?php
$args = array(
'post_type' => 'cases', // enter your custom post type
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page'=> '12', // overrides posts per page in theme settings
);
//query_posts($args);
$loop = new WP_Query( $args );
print_r($loop);
if( $loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post(); //global $post;
$fields = get_fields();
?>
<li>
<div class="container-fluid">
<div class="case-top row">
<div class="col-sm-3 col-xs-12 case-logo">
<figure>
<?php
$thumb_src = wp_get_attachment_url( get_post_thumbnail_id(get_the_ID()) );
function percent_calc($before, $after) {
return 100*$after/$before;
}
?>
<img src="<?php echo $thumb_src; ?>" alt="<?php the_title(); ?>">
</figure>
</div>
<div class="col-sm-7 col-xs-12 case-title">
<?php the_content(); ?><br><br>
<div class="case-review-link">Отзыв клиента
<div class="case-review">
<div class="case-review-wrap">
<p><?php echo $fields['review_text']; ?></p>
<div class="reviewer-info">
<img src="<?php echo $fields['reviewer_photo']['url']; ?>" alt="<?php echo $fields['reviewer_name']; ?>">
<p><?php echo $fields['reviewer_name']; ?></p>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-2 col-xs-0"></div>
</div>
<div class="case-table-wrap">
<div class="row descr-head-row">
<div class="col-sm-3 col-xs-0"></div>
<div class="col-sm-3 col-xs-6 row-descr-been">было</div>
<div class="col-sm-3 col-xs-6 row-descr-became">стало</div>
<div class="col-sm-3 col-xs-0"></div>
</div>
<div class="row">
<div class="col-sm-3 col-xs-12 row-title">
<div class="traffic">
<p>Зашли на сайт</p>
<p>Трафик за месяц</p>
</div>
</div>
<div class="col-sm-3 col-xs-6 row-been"><span>было</span><p><?php echo $fields['month_traffic_before']; ?></p></div>
<div class="col-sm-3 col-xs-6 row-became"><span>стало</span><p><?php echo $fields['month_traffic_after']; ?></p></div>
<div class="col-sm-3 col-xs-12 row-percentage"><p>+ <?php echo percent_calc($fields['month_traffic_before'], $fields['month_traffic_after']); ?>%</p></div>
</div>
<div class="row">
<div class="col-sm-3 row-title">
<div class="offer-want">
<p>Захотели заказать</p>
<p>Добавление в корзину</p>
</div>
</div>
<div class="col-sm-3 col-xs-6 row-been"><span>было</span><p><?php echo $fields['basket_add_before']; ?></p></div>
<div class="col-sm-3 col-xs-6 row-became"><span>стало</span><p><?php echo $fields['basket_add_after']; ?></p></div>
<div class="col-sm-3 col-xs-12 row-percentage"><p>+ <?php echo percent_calc($fields['basket_add_before'], $fields['basket_add_after']); ?>%</p></div>
</div>
<div class="row">
<div class="col-sm-3 row-title">
<div class="offers">
<p>Заказали</p>
<p>Конверсия сайта</p>
</div>
</div>
<div class="col-sm-3 col-xs-6 row-been"><span>было</span><p><?php echo $fields['site_conversion_before']; ?></p></div>
<div class="col-sm-3 col-xs-6 row-became"><span>стало</span><p><?php echo $fields['site_conversion_after']; ?></p></div>
<div class="col-sm-3 col-xs-12 row-percentage"><p>+ <?php echo percent_calc($fields['site_conversion_before'], $fields['site_conversion_after']); ?>%</p></div>
</div>
<div class="row">
<div class="col-sm-3 row-title">
<div class="payed">
<p>Оплатили</p>
<p>Конверсия покупки</p>
</div>
</div>
<div class="col-sm-3 col-xs-6 row-been"><span>было</span><p><?php echo $fields['purchase_conversion_before']; ?></p></div>
<div class="col-sm-3 col-xs-6 row-became"><span>стало</span><p><?php echo $fields['purchase_conversion_after']; ?></p></div>
<div class="col-sm-3 col-xs-12 row-percentage"><p>+ <?php echo percent_calc($fields['purchase_conversion_before'], $fields['purchase_conversion_after']); ?>%</p></div>
</div>
</div>
<div class="row conclusion">
<div class="col-sm-6 col-xs-12">
<p>Сделанные работы:</p>
<div class="filters item-filters">
<?php echo $fields['work_done']; ?>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="aud-price col-sm-5 col-xs-12">
<p>Стоимость аудита:</p>
<p><span style="color: #16a085;font-size: 30px;"><?php echo $fields['audit_price']; ?></span> руб.</p>
</div>
<div class="col-sm-2 col-xs-0"><div class="slash"></div></div>
<div class="aud-time col-sm-5 col-xs-12">
<p>Окупаемость:</p>
<p><span style="color: #16a085;font-size: 30px;"><?php echo $fields['payback']; ?></span></p>
</div>
</div>
</div>
</div>
</li>
<?php
endwhile;
endif;
//wp_reset_query();
wp_reset_postdata();
?>
</ul>
<!-- После этого идёт дальнейший контент в вёрстке, который не выводится -->
<div class="case-nav custom-case-slider-nav">
<a href="" class="flex-prev left"></a>
<span class="case-index">1</span><span class="case-amount">/5</span>
<a href="" class="flex-next right"></a>
</div>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
Answer the question
In order to leave comments, you need to log in
Friend, why are you defining a function in a loop?
$thumb_src = wp_get_attachment_url( get_post_thumbnail_id(get_the_ID()) );
function percent_calc($before, $after) {
return 100*$after/$before;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question