I have made a custom post type archive page, but can't make the wordpress pagination work. So far the code I have is the following, but clicking on page navigation just tells me that the page cannot be found. The Custom Post Type is made with Advanced Custom Fields plugin.
<?php
$custom_query_args = (array(
'post_type' => 'kampaania'
));
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$custom_query = new WP_Query( $custom_query_args );
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
?>
<main id="content" class="site-main">
<?php if ( apply_filters( 'hello_elementor_page_title', true ) ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="entry-title">', '</h1>' );
the_archive_description( '<p class="archive-description">', '</p>' );
?>
</header>
<?php endif; ?>
<div class="page-content">
<?php
while ($custom_query->have_posts() ) {
$custom_query->the_post();
$post_link = get_permalink();
?>
<article class="post">
<div class="post-thumbnail">
<?php
if ( has_post_thumbnail() ) {
printf( '<a href="%s">%s</a>', esc_url( $post_link ), get_the_post_thumbnail( $post, 'large' ) );
} ?>
</div>
<div class="card-body">
<?php
$field = get_field_object('kampaania_periood');
$field2 = get_field_object('kampaanias_kauplused');
?>
<div class="bpost-title">
<?php
printf( '<h2 class="%s"><a href="%s">Kampaania nimi: %s</a></h2>', 'entry-title', esc_url( $post_link ), wp_kses_post( get_the_title() ) );
?>
</div>
<p class="kamp-period">
<span class="kamp-period-head"><?php echo $field['label']; ?></span> <?php echo $field['value']; ?>
</p>
<p class="post-excerpt">
<?php the_excerpt(); ?>
</p>
<p class="kamp-kaup">
<span class="kamp-period-head"><?php echo $field2['label']; ?></span> <?php echo $field2['value']; ?>
</p>
<a href="<?php the_permalink(); ?>" class="btn-closer">Osale kampaanias</a>
</div>
</article>
<?php } ?>
</div>
<?php wp_link_pages(); ?>
<?php
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) :
?>
<nav class="pagination">
<?php /* Translators: HTML arrow */ ?>
<div class="nav-previous"><?php next_posts_link( sprintf( __( '%s Vanemad kampaaniad', 'hello-elementor-child' ), '<span class="meta-nav">←</span>' ) ); ?></div>
<?php /* Translators: HTML arrow */ ?>
<div class="nav-next"><?php previous_posts_link( sprintf( __( 'Uuemad kampaaniad %s', 'hello-elementor-child' ), '<span class="meta-nav">→</span>' ) ); ?></div>
</nav>
<?php endif; ?>
</main>
I have made the template using Hello Elementor child theme and their archive template.
Any ideas, on how to get the pagination working?