I've a custom theme based on this one http://underscores.me/. I've a custom taxonomy called event-bucket and custom post_type called bucket. I've a page where I can see all the buckets of an event-bucket:


This page works well and I use the_posts_navigation() for the navigation and when I click on it it redirect to mybesite.com/bucket/my-event-bucket/page/2 wich come to a 404 page. BUT when I put manually an url like mybesite.com/bucket/my-event-bucket?page=2 It come to the right page.

Do you know how can I fix the "Older Post" button working properly ?

Here is my archive.php the template called by mybesite.com/bucket/my-event-bucket/

 * The template for displaying archive pages.
 * @link https://codex.wordpress.org/Template_Hierarchy
 * @package socialite

get_header('bucket'); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

        if ( have_posts() ) : ?>

            <header class="page-header">
                    the_archive_title( '<h1 class="page-title">', '</h1>' );
                    the_archive_description( '<div class="archive-description">', '</div>' );
            </header><!-- .page-header -->


            $paged = (get_query_var('page')) ? get_query_var('page') : 1;
            query_posts( array( 'post_type' => 'bucket', 'paged' => $paged ) );

            /* Start the Loop */
            while ( have_posts() ) : the_post();

                 * Include the Post-Format-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 Format name) and that will be used instead.
                get_template_part( 'template-parts/content', get_post_format() );


        else :

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

        endif; ?>

        </main><!-- #main -->
    </div><!-- #primary -->

// get_sidebar();
  • How have you built bucket/my-event-bucket/? That URL suggets the page for a single bucket called my-event-bucket. The proper way to have a paginated archive of buckets in a the my-event-bucket term is to go to event-bucket/my-event-bucket/ which will use taxonomy-event-bucket.php for the template (or fall back to archive.php/index.php). – Jacob Peattie Sep 5 '17 at 11:38
  • any code? any research? In general the pagination API will not work nicely with queries which are not the main query – Mark Kaplun Sep 5 '17 at 12:29
  • @JacobPeattie , I took part of this project in the middle of the developpment. I know that to access an event-bucket called event1 the url is mysite/bucket/event1. And the template for this page is archive.php – Kahikwic Sep 5 '17 at 12:46
  • @MarkKaplun Which file do you want ? – Kahikwic Sep 5 '17 at 12:50
  • the relevant code, and I do not "want". when you ask a question relating to specific code, it is unlikely you will get a useful unswer when no one knows what is the code – Mark Kaplun Sep 5 '17 at 12:56

query_posts should never be used. Right now you are getting pagination urls that are relevent to whatever you feed to the query_posts but they lack the url of the page.

In general, regardless of the query_posts issue, pagination in internal loops should use pagination parameters which are different than those used by wordpress core, or in other words, you need to construct the pagination urls yourself, and depending on whether you want the pretty url, might need to add rewrite rulr for it. You might get lucky and be ble to use one of the core paging parameters, but that is hacky (although several answers here recommend doing that, so maybe success rate are better than I think).

What you really should do, as you basically create a new type of archive pages, is to add a rewrite rule for those types of urls, and use the pre_get_posts filter to properly populate the loop, and template_redirect to intercept such pages to use some template of your own. This is the cleanest way, but not necessarily the easiest one :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.