plugins - PageNavi redirects to 404 when used as archive page

admin2025-06-04  5

I'm using a page as archive for a custom post type called event.

register_post_type('event', array(
    'labels' => array(
        'name' => 'Événements',
        'singular_name' => 'Événement',
    ),
    'public' => true,
    'has_archive' => false,
    'hierarchical' => false,
    'menu_icon' => 'dashicons-calendar-alt',
    'rewrite' => array(
        'with_front' => false,
        'slug' => 'evenements'
    )
));

Then, I defined this page template to template-event.php, where I use the following code to loop through post types.

$args = array(
    'post_type'      => 'event',
    'posts_per_page' => 6,
    'paged'          => get_query_var('paged')
);

$the_query = new WP_Query( $args );

if( $the_query->have_posts() ) :

    while ( $the_query->have_posts() ) : $the_query->the_post();

        the_title();

    endwhile;

    wp_pagenavi( array( 'query' => $the_query ) );
    wp_reset_postdata();

endif;
?>

This code works great for my home.php page, but not for this one.
Any idea why?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749024197a315713.html

最新回复(0)