@anmkh

Как решить проблему с пагинацией Wordpress?

Как решить проблему с пагинацией? При выборе фильтра, пропадает кнопка "Загрузить еще"
Видел, что это из за query_posts.
Прошу, помогите переделать код

<section id="primary" class="news">
    <div class="container">
        <?php if ( have_posts() ) : ?>

        <div class="news__head">
            <h2 class="title"><?php single_cat_title();?></h2>

            <?php global $query_string; // параметры базового запроса
query_posts($query_string.'&'.$order); // базовый запрос + свои параметры
?>

            <form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="post-date-filter">
                <div class="news__select">
                    <!-- Дата -->
                    <div class="__select" data-state="">
                        <div class="__select__title" data-default="Option 0">Выберите дату</div>
                        <div class="__select__content">

                            <input id="singleSelect0" class="__select__input" type="radio" name="singleSelect" checked>
                            <label for="singleSelect0" class="__select__label">Option 0</label>

                            <input id="singleSelect1" class="__select__input" type="radio" name="date" value="ASC">
                            <label for="singleSelect1" class="__select__label">Дата: по возрастанию</label>

                            <input id="singleSelect3" class="__select__input" type="radio" name="date" value="DESC"
                                selected="selected">
                            <label for="singleSelect3" class="__select__label">Дата: по убыванию</label>

                        </div>
                    </div>
                    <!-- Конец Дата -->


                    <!-- Категория -->
                    <?php
if( $terms = get_terms( 'post_tag', 'orderby=name' ) ) :
    ?>
                    <div class="__select-two" data-state="">
                        <div class="__select__title-two" data-default="Option 0">Выберите тему мероприятия</div>
                        <div class="__select__content-two">

                            <input id="singleSelect5" class="__select__input-two" type="radio" name="singleSelect2"
                                checked>
                            <label for="singleSelect5" class="__select__label-two">Option 0</label>

                            <?php
  foreach ( $terms as $term ) :
    ?>
                            <input id="<?php echo $term->term_id ?>" class="__select__input-two" type="radio"
                                name="categoryfilter" value="<?php echo $term->term_id ?>">
                            <label for="<?php echo $term->term_id ?>" class="__select__label-two"
                                value="<?php echo $term->term_id ?>"><?php echo $term->name ?></label>

                            <?php
  endforeach;
  ?>
                        </div>
                    </div>
                    <?php
endif;
?>
                    <!-- Конец Категория -->

                </div>
                <button type="submit" class="filter-btn">Применить фильтр</button>
                <input type="hidden" name="action" value="customfilter">
            </form>

        </div>

        <div class="news__content" id="filtering-results">
            <?php
			/* Start the Loop */
			while ( have_posts() ) :
				the_post();

				/*
				 * Include the Post-Type-specific template for the content.
				 * If you want to override this in a child theme, then include a file
				 * called content-___.php (where ___ is the Post Type name) and that will be used instead.
				 */
				get_template_part( 'template-parts/content-news', get_post_type() );

			endwhile;
		else :

			get_template_part( 'template-parts/content', 'none' );

		endif;
		?>
            <?php
                global $wp_query;
 
                // текущая страница
                $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
                // максимум страниц
                $max_pages = $wp_query->max_num_pages;
                 
                // если текущая страница меньше, чем максимум страниц, то выводим кнопку
                if( $paged < $max_pages ) {
                    echo '<div id="loadmore" style="text-align:center;">
                        <a href="#" data-max_pages="' . $max_pages . '" data-paged="' . $paged . '" class="button">Загрузить ещё</a>
                    </div>';
                } ?>

        </div><!-- #news__content -->
    </div><!-- #container -->
</section><!-- #section -->
  • Вопрос задан
  • 45 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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