M
M
Max Zhukov2018-02-24 18:17:31
WordPress
Max Zhukov, 2018-02-24 18:17:31

Why isn't all post data showing up?

When displaying the feedback block in the page template, everything is fine:

<div class="recall_block" style="background-image: url('<?php echo get_template_directory_uri() ?>/assets/img/bg_recall.jpg');">
        <div class="container">
          <div class="custom_title text-center">
            <h2>Отзывы клиентов</h2>
          </div>
          <div class="row">
              <?php

              // параметры по умолчанию
              $args = array(
                  'numberposts' => 3,
                  'post_type'   => 'reviews',
                  'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
              );

              $posts = get_posts( $args );

          foreach($posts as $post): setup_postdata($post)?>
            <div class="col">
              <div class="recall">
                <div class="picture">
                    <img src="<?php the_post_thumbnail_url( 'full' );?>">
                </div>
                <div class="name"><?php the_title(); ?></div>
                <p><?php echo get_the_content(); ?></p>
              </div>
            </div>
              <?php  endforeach;
              wp_reset_postdata(); // сброс
              ?>
          </div>
          <div class="row">
            <div class="col text-center">
              <div class="watch_all"><a href="#/reviews/">Смотреть все</a></div>
            </div>
          </div>
        </div>
      </div>

5a9181400ce7d259441578.png
And when outputting this code through the function, then all the data is not displayed:
if ( ! function_exists( 'mebel_reviews' ) ) {

function mebel_reviews(){
?>
          <div class="recall_block" style="background-image: url('<?php echo get_template_directory_uri() ?>/assets/img/bg_recall.jpg');">
        <div class="container">
          <div class="custom_title text-center">
            <h2>Отзывы клиентов</h2>
          </div>
          <div class="row">
              <?php

              // параметры по умолчанию
              $args = array(
                  'numberposts' => 3,
                  'post_type'   => 'reviews',
                  'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
              );

              $posts = get_posts( $args );

          foreach($posts as $post): setup_postdata($post)?>
            <div class="col">
              <div class="recall">
                <div class="picture">
                    <img src="<?php the_post_thumbnail_url( 'full' );?>">
                </div>
                <div class="name"><?php the_title(); ?></div>
                <p><?php echo get_the_content(); ?></p>
              </div>
            </div>
              <?php  endforeach;
              wp_reset_postdata(); // сброс
              ?>
          </div>
          <div class="row">
            <div class="col text-center">
              <div class="watch_all"><a href="http://mebel.amtex.by/reviews/">Смотреть все</a></div>
            </div>
          </div>
        </div>
      </div>
<?php
}
}

5a9181eb541d6797599932.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-03-02
@MaksZhukov

Try to add at the beginning of the function global $post;(or before the start of the foreach).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question