0

Я сделал такой WP_Query, но почему-то не выводится пагинация.

В archive-product вывел такой WP Query

  $wp_query = new wp_query( array(
    'post_type'      => 'product',
    'paged' => get_query_var('paged'),
    'posts_per_page' => 9,
    'orderby'      => 'meta_value_num',
    'meta_key'      => 'lenght',
    'meta_query' => array(
    'relation' => 'AND',
        array(
            $year_query,
            $lenght_query,
        )
    ),
    'tax_query' => array(
        'relation' => 'AND',
        array(

        'taxonomy' => 'product_cat',
                        'field' => 'id',
                        'terms' => $cateID

        ),
        
        $builder_query, 
        $guests_query, 
        $location_query, 

        $cond_query, 
        $cabins_query, 
        $type_query,
       
    ),

    ));

if ( $wp_query->have_posts() ) : ?>
    <!-- цикл -->
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); 
                 wc_get_template_part( 'content', 'product' );
      endwhile; ?>

      
   
    <!-- конец цикла -->
    <?php wp_reset_query(); ?>

<?php endif; ?>

В function.php вставил такой код для вывода пагинации (украдено с WP KAMA)

function my_pagenavi() {
    global $wp_query;

    $big = 999999999; // уникальное число для замены

    $args = array(
        'base'    => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
        'format'  => '',
        'current' => max( 1, get_query_var('paged') ),
        'total'   => $wp_query->max_num_pages,
    );

    $result = paginate_links( $args );

    // удаляем добавку к пагинации для первой страницы
    $result = preg_replace( '~/page/1/?([\'"])~', '', $result );

    echo $result;
}

Но пагинация не выводится.

В чем может быть проблема?

1

1 ответ 1

0

Функцию my_pagenavi() вызвайте там, где должна быть пагинация.

Вот так:

echo my_pagenavi();

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.