The WP Setup

I created a template, broadcast-archive-template.php, that contains code that functions as a custom post type archive page. We set the page template to the template in the WP admin to put the archive template on whichever page we want. We set it up this way so we can make changes to the header image, page title, etc... without going into the code and making the change.

The Problem

I am having an issue where when I setup my pagination, the "Next Page" link correctly redirects to /custom-post-type-name/page/2 but since it is a page template, it returns a 404 and not the next page of posts.

The Code

Template Code

<h2 id="aligncenter"><?php the_sub_field('recent_posts_header')?></h2>
<hr class="recent-posts-rule">
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array (
    'nopaging' => false,
    'paged' => $paged,
    'order' => 'DESC',
    'posts_per_page' => 3,
    'post_type' => array(
// the queries
$wp_query = new WP_Query( $args );?>
<div> <?php
    /// The call to insert recent posts on the home page
    if ( $wp_query->have_posts() ) :
        while ( $wp_query->have_posts() ) : $wp_query->the_post() ?>

        <?php $header_image_b_values = get_field('header_image_broadcast');
        $recent_post_thumbnails = esc_attr($header_image_b_values['sizes']['large'])?>
        <div class="four-columns ">
            <div class="recent-posts" id="overlay">
                <h3 id="recent-post-block"><?php the_title();?></h3>
                <a class="blue-wisco-button" id="recent-post-button" href="<?php get_post_permalink()?>">Read More</a>
                <img id="recent-post-image" src="<?php echo $recent_post_thumbnails;?>">
        echo "hello";

    else : ?>
        <p><?php __('No Broadcasts to Show'); ?></p>
    <?php endif;?>

The CPT Code

function broadcast_post_types() {
$labels = array(
    'name'               => 'Broadcasts',
    'singular_name'      => 'Broadcast',
    'menu_name'          => 'Broadcasts',
    'name_admin_bar'     => 'Broadcasts',
    'add_new'            => 'Add New Broadcast',
    'add_new_item'       => 'Add New Broadcast',
    'new_item'           => 'New Broadcast',
    'edit_item'          => 'Edit Broadcast',
    'view_item'          => 'View Broadcast',
    'all_items'          => 'All Broadcasts',
    'search_items'       => 'Search Broadcasts',
    'parent_item_colon'  => 'Parent Broadcasts:',
    'not_found'          => 'No Broadcasts found.',
    'not_found_in_trash' => 'No Broadcasts found in Trash.'

$args = array(
    'public'      => true,
    'labels'      => $labels,
    'description' => 'These broadcasts are a replay of Wisco Radio Content',
    'menu_icon'   => 'dashicons-format-video',
    'hierarchical'=> true,
    'has_archive' => false,
register_post_type( 'broadcast', $args );

Is it possible to have a functioning pagination without using the archive.php template or archive-cpt.php template?

  • Why are you using a page template, and not just the correct post type archive template? – Jacob Peattie Jun 8 at 2:59

Your Answer

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

Browse other questions tagged or ask your own question.