Пользовательская проблема разбивки на страницы запроса с параметром php как arg - PullRequest
0 голосов
/ 25 мая 2019

У меня есть цикл с пользовательским запросом. Этот запрос содержит параметры php, которые я получаю из URL с помощью метода GET. Этот код на моей странице цикла:

    $cat = get_queried_object();
    echo '<h1 class="childcatdes">'. $cat->name . '</h1>';
    echo '<p class="childcatdescr">'. $cat->description . '<br><br></p>';
    do_action( 'woocommerce_before_single_product' );

    $posts_per_page = 12;
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;


    $product_args = array(
        'post_type' => 'product',
        'posts_per_page' => $posts_per_page,
        'paged' => $paged,
        'page' => $paged,
        'tax_query' => array(
             'relation' => 'AND',
            array(
              'taxonomy' => 'product_cat',
              'field'    => 'name',
              'terms'    => $cat->name,
            ),
            array(
              'taxonomy' => 'manufacturers',
              'field'    => 'slug',
              'terms'    => $_GET['filter_manufacturers'],
              'operator' => 'IN'
            )
        ),
        'orderby' => 'name',
        'order' => 'ASC',
    );

    $custom_query = new WP_Query( $product_args );

    if($custom_query->have_posts()) {
        echo '<ul';
        while ($custom_query->have_posts() )  : $custom_query->the_post(); 
            echo '<li>';
                $link = get_the_permalink();

                echo '<a href="' . $link . '">' . get_the_title() . '</a>';

            echo '</li>';
        endwhile;


        echo '</ul>';
    }
    else {
        echo 'No post found.';
    }
    ?>
    <nav class="pagination">
        <?php pagination_bar( $custom_query); ?>
    </nav>

И я использую этот код в своем файле functions.php для функции pagination_bar

function pagination_bar( $custom_query) {
    $total_pages = $custom_query->max_num_pages;
    $big = 999999999; // need an unlikely integer
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%',
           'current' => $current_page,
           'format' => 'page/%#%/',
           'total' => $custom_query->max_num_pages,
           'add_args' => array(
               'filter_manufacturers' => $_GET['filter_manufacturers'],
           )
        ));
    }
}

Проблема в том, что нумерация страниц (даже если она считает сообщения правильными на первой странице) не работает правильно. Я получаю ошибку 404 на второй странице.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...