1

I am having a problem with pagination on one of my CPT after assigning the custom page template to a different page with a different slug. It all worked perfectly on the test page I developed it with. Only after the new assignment did I run into this issue for subsequent pages (2,3,etc.). Page 1 still works fine. I did resave the Permalinks in WP after the assignment of the custom page template and cleared and rebuild all caches (WP Rocket, WP Engine, Cloudflare).

I also tried modifying the CPT by removing 'hierarchical' => true and 'capability_type' => 'page' but that did seem to have any effect either.

I am sure I am missing clearing something somewhere as it was working perfectly before the template reassignment.

You can see the working one here (click on '2' below the pictures): https://totalk9focus.com/test-page/ You can see the non-working one here (click on '2' below the pictures): https://totalk9focus.com/client-pictures/

I hope someone can help me sort this out.

Attached code sections: Definition of the CPT in functions.php | Query for the pages | Footer section with pagination links

    register_post_type( 'pictures',
        array( 
                'labels'            => array(
                                        'name'          => __( 'Pictures' ),
                                        'singular_name' => __( 'Picture' )          
                                    ),
                '_builtin'          => false,
                'public'            => true, 
                'show_ui'           => true,
                'show_in_nav_menus' => false,
                'menu_position'       => 6,
                'hierarchical'      => true,
                'capability_type'   => 'page',
                'menu_icon'           => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-format-image' : '',
                'rewrite'           => array(
                    'slug'       => 'client-pictures',
                    'with_front' => FALSE,
                ),
                'supports' => array(
                        'title',
                        'editor',
                        'thumbnail',
                        'excerpt',
                        'custom-fields',
                        'post-formats'
                        )
                    ) 
                );
}
add_action('init', 'my_post_type_client_pictures'); ```

**Query for the pages**

``` get_header(); 

/* Get Pictures */
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
    'post_type' => 'pictures',
    'post_status' => 'publish',
    'orderby' => 'publish_date',
    'order' => 'DESC',
    'posts_per_page' => 12,
    'paged' => $paged,
);
$arr_posts = new WP_Query( $args ); ```

**Footer section with pagination links**

```                         $total_pages = $arr_posts->max_num_pages;

                        if ($total_pages > 1){

                            $current_page = max(1, get_query_var('paged'));

                            echo paginate_links(array(
                                'base' => get_pagenum_link(1) . '%_%',
                                'format' => 'page/%#%/',
                                'current' => $current_page,
                                'total' => $total_pages,
                                'prev_text'    => __('« prev'),
                                'next_text'    => __('next »'),
                            ));
                        } ```

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.