D
D
Dmitry Zhukov2018-04-20 10:56:13
WordPress
Dmitry Zhukov, 2018-04-20 10:56:13

How to fix 404 error on pagination?

Hello. I made an arbitrary post type (files), created a separate archive file for it (archive-files.php). Pagination appears, but the transition 404 error. I output the records in the archive file like this:

<div id="content" class="content" role="main">

<?php if( have_posts() ){  $args = array('post_type' => 'files', 'posts_per_archive_page' => 2); query_posts( $args );?>
    <ul class="files-list">
    <?php while( have_posts() ){ the_post(); ?>
        <li>
          Тут вывод произвольных полей и верстка.
        </li>
    <?php }  /* конец while */ ?>
    </ul>

    <div class="navigation">
        <?php the_posts_pagination(); ?>
    </div>

<?php
    wp_reset_query(); } // конец if
else
echo "<h4>Записей нет.</h4>"; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-04-20
@dreamfdr

Never use query_posts. Never. Broken pagination is the first problem that pops up from query_posts. What you need (limited to 2 posts per page) is done via the pre_get_posts hook .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question