I
I
it_pear_yurec2018-07-21 22:50:52
WordPress
it_pear_yurec, 2018-07-21 22:50:52

Why is wp_query not being reset?

How to reset wp_query function when clicking on category output?
5b538e5ff1928018572974.jpeg

<?php 
              $args = array(
                'post_type' => 'post',
                'meta_key' => 'post_price',
                'meta_query' => array(
                  'key' => 'post_price',
                  'value' => '0',
                  'compare' => '>',
                  'type' => 'NUMERIC',
                ),
                'order' => 'ASC',
                'suppress_filters' => false,
                'orderby' => 'meta_value_num',

              );
             ?>
             <?php $query = new WP_Query( $args ); ?>
            <?php  if ($query->have_posts()) { while ($query->have_posts()) {$query->the_post(); ?>

            <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <div class="catalogSec-Item">
                <div class="catalogSec-img">
                  <?php the_post_thumbnail( 'thambnail' ) ?>
                </div>
                <div class="catalogSec-descript">
                  <p class="catalogSec-descript__name"><?php echo get_short_title(36); ?></p>
                  <!-- <p class="catalogSec-descript__functional"><?php // the_category( $separator = '/', ''); ?></p> -->
                  <p class="catalogSec-descript__price"><?php the_field('post_price'); ?> Руб.</p>
                </div>
                <div class="catalogSec-descript-btn">
                  <a href="<?php the_permalink(); ?>" class="btn-blue catalogSec-descript__btn">Купить</a>
                </div>
              </div>
            </div>

  <?php } // конец while ?>
    <?php the_posts_pagination(); ?>
  <?php }  wp_reset_query(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yunus Gaziev, 2018-07-22
@it_pear_yurec

The request did not specify parameters for the product category . See Taxonomy Parameters . Those. you need to determine where you are, in a category or not, and if you are in a category, then add parameters from to the query to select posts from the current category.
But, because it can be seen that all the salt is in the price of the product, it is better to modify the main query WordPress comment-24037 only for the main query, without search, the search is already subject to the main query.
And why check for a price greater than 0? You can set the status to a draft for a record if the price is 0.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question