WordPress.org

Ready to get started?Download WordPress

Forums

custom post type pagination broken (2 posts)

  1. thomas
    Member
    Posted 7 months ago #

    hello !
    here's what I'm trying to do :

    I have a custom post type (epicerie)
    the posts are displayed on a custom page template like this :

    <?php
    	$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    	$query = new WP_Query( array( 'paged' => $paged, 'post_type' => 'epicerie' ) );
    ?>
    
    <?php if ($query->have_posts()) : ?>
    <?php while ($query->have_posts()) : $query->the_post(); ?>
    
    	// display my elements
    
    <?php endwhile; ?>
    <?php endif; ?>

    next I add the nav links, and they show up :

    <p class="prev"><?php previous_posts_link( __( 'Produits précédents','my_theme'), $query->max_num_pages ); ?></p>
    <p class="next"><?php next_posts_link( __( 'Produits suivants','my_theme'), $query->max_num_pages ); ?></p>

    First page is okay, posts are displayed, but when I clic the next post link it's a 404...

    body class of the first page is :
    <body class="page page-id-14 page-template page-template-page-epicerie-php">

    and page 2 is :
    <body class="error404 paged-2">

    I'm clearly missing something, but what ? a template ?
    any idea ?

  2. thomas
    Member
    Posted 7 months ago #

    I've just tried with :
    'has_archive' => true
    added in my functions.php post-type init.
    and a template : archive-epicerie.php

    And it's working this way.
    But I still don't understand why it's not working with page templates...

    If someone's got an idea !
    thanks

Reply

You must log in to post.

About this Topic

Tags