R
R
Roma Ishutin2020-10-05 14:11:30
WordPress
Roma Ishutin, 2020-10-05 14:11:30

404 page when following pagination links?

Hello, I made pagination for custom post types. Pagination appeared, but when you click on the links, it redirects to a 404 page. The permalinks are "/%category%/%postname%/", I tried adding some code to functions.php, it didn't help.
Post and pagination output code.

$query = new WP_Query( [
                'post_type'      => 'blog',
                'posts_per_page' => 2,
                'paged'          => get_query_var( 'page' ),
            ] );

            // Обрабатываем полученные в запросе продукты, если они есть
            if ( $query->have_posts() ) {
                while ( $query->have_posts() ) {
                    $query->the_post();?>
                    <p style="color: green"><?php the_title();?></p>
                <?}

                wp_reset_postdata();
            }

            // Выводим пагинацию, если продуктов больше запрошенного количество
            echo paginate_links( [
                'base'    => user_trailingslashit( wp_normalize_path( get_permalink() .'/%#%/' ) ),
                'current' => max( 1, get_query_var( 'page' ) ),
                'total'   => $query->max_num_pages,
            ] );

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question