Posts per Page not working

Question

I have custom post type of reviews, I want to limit the number of posts on the page, the standard methods do not work, please help!

<?php
/* Template Name: reviews */
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
    'posts_per_page' => 21,
    'paged'          => $paged
);

$the_query = new WP_Query( $args );
get_header(); ?>

    <div class="container category_reviews_inner">
        <main id="main" class="site-main clearfix">
            <div class="main-content" id="content">
                <header class="entry-header">
                    <h1 class="entry-title page-title">Отзывы</h1>
                </header>
                <div class="entry-content">
                    <div class="easy_testimonials_grid easy_testimonials_grid_1 easy_testimonials_grid_responsive">

                        <?php $arg_cat = array(
                            'order'        => 'DESC',
                            'hide_empty'   => 1,
                            'exclude'      => '',
                            'include'      => '',
                            'taxonomy'     => 'reviews_Categories',
                            'posts_per_page' => 21,
                        );
                        $categories = get_terms( $arg_cat );?>

                        <?php if( $categories ){foreach( $categories as $cat ){
                            $arg_posts =  array(
                                'post_type' => 'reviews',
                                'post_status' => 'publish',
                                'posts_per_page' => 21,
                                'order'    => 'DESC',
                                'tax_query' => array(
                                    array(
                                        'taxonomy' => 'reviews_Categories',
                                        'field'    => 'slug',
                                        'posts_per_page' => 21,
                                        'terms'    => $cat->slug,
                                    )
                                ),
                            );
                            $query = new WP_Query($arg_posts);

                            if ($query->have_posts() ) : ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                                
                                <blockquote class="easy_testimonial for_title">
                                    <div class="easy_testimonial_image_wrapper"></div>
                                    
                                    <div class="testimonial_body">
                                        <div class="review_title"><?= the_field('review_title') ?></div>
                                    </div>
                                </blockquote>
                                <div class="easy_testimonials_grid_row easy_testimonials_grid_row_1">
                                    <div class="easy_testimonials_grid_cell">
                                        <div class="style-clean_style  show_thumbs show_title show_position hide_date stars_rating hide_other easy-t-category-kurs-magiya-schastya  easy_t_single_testimonial">
                                            <blockquote class="easy_testimonial">
                                                <div class="easy_testimonial_image_wrapper">
                                                    <?php if (has_post_thumbnail()): the_post_thumbnail('thumbnail'); else : ?>
                                                        <img width="400" height="400" src="<?php bloginfo('template_url'); ?>/imgs/user_icon.png" alt="Отзовик"/>
                                                    <?php endif ?>
                                                </div>
                                                <p class="testimonial_author">
                                                    <cite>
                                                        <span class="testimonial-client"><?php the_title(); ?></span>
                                                    </cite>
                                                </p>
                                                <div class="testimonial_body">
                                                    <?php the_content(); ?>
                                                </div>
                                                <div class="reviews_link">
                                                    <a href="/reviews-category/<?= $cat->slug ?>"
                                                       class="easy_testimonial_title w-auto">&nbsp;
                                                        #<?= $cat->name ?></a>
                                                </div>
                                                <div class="easy_t_clear"></div>
                                            </blockquote>
                                        </div>
                                    </div>
                                </div>

                            <?php endwhile; endif; } } ?>
                        <div class="all_categories">
                            <h2 class="entry-title page-title" style="text-align: center">Отзывы о курсе:</h2>
                            <?php
                            $term    = get_queried_object();
                            $term_id = ( isset( $term->term_id ) ) ? (int) $term->term_id : 0;

                            $categories = get_categories( array(
                                'taxonomy'   => 'reviews_Categories',
                                'orderby'    => 'DESC',
                                'parent'     => 0,
                                'hide_empty' => 1,
                            ) );
                            ?>


                            <?php
                            foreach ( $categories as $category )
                            {
                                $cat_ID        = (int) $category->term_id;
                                $category_name = $category->name;

                                $cat_class = ( $cat_ID == $term_id ) ? 'active' : 'not-active';

                                if ( strtolower( $category_name ) != 'uncategorized' )
                                {?>
                                    #<a href="/reviews-category/<?= $category->slug ?>" class="easy_testimonial_title w-auto"><?= $category->name ?>&nbsp;</a>
                                <?php  }
                            }
                            ?>

                        </div>
                        <div class="easy_t_pagination">
                            <?php
                           the_posts_navigation( array(
                                'prev_text' => '&larr; ' . esc_html__( 'Предыдущие', 'eightydays' ),
                                'next_text' => esc_html__( 'Новые', 'eightydays' ) . '&rarr;',
                            ) );
wp_reset_postdata();
                            ?>
                        </div>
                    </div>
                </div>
            </div>

        </main>
    </div>

<?php
get_footer();
0
Dmitry 4 months 0 Answers 24 views 0

Leave an answer