@Concencuc

Как в цикле выводить вначале посты Новинок, а потом все остальные?

60b88738476b4593895604.jpeg
Сейчас посты выводятся вот так c инфинити скроллом.
$cat_id = get_query_var('category_products');
$posts = new WP_Query(array(
          'post_type' => 'products',
          'category_products' => $cat_id,
          'orderby' => 'date',
          'posts_per_page' => 999,
          )
        );

$total = $posts->post_count;
$count = 0;
$number = 11; 
if($posts->have_posts()) : ?>
  <div class="catalog_products flex row wrap">
    <div class="load-more-wrap">
  <?php while($posts->have_posts()): $posts->the_post(); ?>
карточка товара
      <?php if ($count == $number) {
          // we've shown the number, break out of loop
          break;
      } ?> 
  <?php $count++; endwhile; ?>
    </div>
<a id="catalog-load-more" class="btn view-more" style="margin: 0 auto;" href="javascript: products_show_more();" <?php if ($total < $count) { ?> style="display: none;"<?php } ?>><?php the_field('показать_больше_кнопка', 'option'); ?></a>
  </div>
<?php endif; wp_reset_query(); ?>
<script type="text/javascript">
    var my_repeater_field_post_id = <?php echo $post->ID; ?>;
    var my_repeater_field_offset = <?php echo $number + 1; ?>;
    var my_repeater_field_nonce = '<?php echo wp_create_nonce('my_repeater_field_nonce'); ?>';
    var my_repeater_ajax_url = '<?php echo admin_url('admin-ajax.php'); ?>';
    var my_repeater_more = true;
    
    function products_show_more() {
        
        // make ajax request
        jQuery.post(
            my_repeater_ajax_url, {
                // this is the AJAX action we set up in PHP
                'action': 'products_show_more',
                'post_id': my_repeater_field_post_id,
                'offset': my_repeater_field_offset,
                'nonce': my_repeater_field_nonce
            },
            function (json) {
                // add content to container
                // this ID must match the containter 
                // you want to append content to
                jQuery('.catalog_products .load-more-wrap').append(json['content']);
                // update offset
                my_repeater_field_offset = json['offset'];
                // see if there is more, if not then hide the more link
                if (!json['more']) {
                    // this ID must match the id of the show more link
                    jQuery('#catalog-load-more').css('display', 'none');
                }
            },
            'json'
        );
    }
</script>

Я пробовал создать два массива и объединить их, но у меня не работают эти параметры
'tag' => '22'
'tag__not_in' => 22

Подскажите пожалуйста, как выводить вначале Новинки?
  • Вопрос задан
  • 76 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы