For a project I have created a custom post type called "episodes", which is registered like this.
register_post_type( 'episodes', array( 'labels' => array( 'name' => __( 'Episodes' ), 'singular_name' => __( 'Episode' ) ), 'public' => true, 'has_archive' => false, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'episodes'), ) );
I have also created a page called episodes. The idea is that I want a page with some basic information and underneath a grid with 8 episodes which can be clicked through using pagination. To be clear, the content of the episodes page should alway show, even on page 2 or 3 of the grid.
To achieve this I created a
page-episodes.php file, copied the content of
page.php and added the following code to the page:
<?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'post_type' => 'episodes', 'posts_per_page' => 8, 'paged' => $paged, ); $query = new WP_Query( $args ); ?> <div class="row"> <?php if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?> <div class="col-3 episode"> <a href="<?php the_permalink()?>"> <span class="episodeNumber"><?php echo get_field("episode_number", $post->ID)?></span> <h1><?php the_title() ?></h1> </a> </div> <?php endwhile; endif; ?> </div> <div class="row"> <div class="col-12 pagination"> <?php echo paginate_links(); ?> </div> </div>
But whenever I use the pagination and go to
/episodes/page/2 for example the page returns the
I hope I have given you enough information, if not please ask. I would really like to know what I'm doing wrong here.