0

I have a custom post type for frequently asked questions, called Question. Its archive is at /faq/.

Page 1 and 2 of the archive currently show the same content. I did some digging and on page 1, is_paged() returns as false, and $wp_query->query_vars['paged'] returns as 0, whereas on page 2 they return as true and 2 respectively (as expected).

I do have a custom archive template called archive-question.php, but this issue occurs even if using the default index.php. There is no custom query, just trying to use the default archive functionality.

Other CPTs used on the site do not have this issue.

Any suggestions as to what could be causing it would be a big help!

Template code for index.php:

<div class="small-12 medium-10 xlarge-8 columns">

    <main class="nested row align-justify">
        <div class="small-12 columns">
            <?php
            if ( have_posts() ) {
                /*
                global $wp_query;
                print_r($wp_query->query_vars['paged']);
                if(is_paged()) {
                    echo "Yep, paged";
                } else {
                    echo "Nope, not paged";
                } */
                // Start the Loop
                while ( have_posts() ) : the_post();
                    get_template_part('excerpts/excerpt-list');
                endwhile;
            } else {
                get_template_part('template-parts/nothing-found');
            } // End have_posts() check.
            ?>
        </div>
    </main>

</div>

<?php // Display navigation to next/previous pages when applicable 
if ( is_paged() ) { ?>
    <nav id="post-nav" class="row align-center align-justify">
        <div class="post-previous columns"><?php next_posts_link( __( '&larr; Older posts', '' ) ); ?></div>
        <div class="post-next columns"><?php previous_posts_link( __( 'Newer posts &rarr;', '' ) ); ?></div>
    </nav>
<?php } ?>

Edited the above to remove custom pagination function, as this code has been tested without it and it still occurs, so I have removed it for clarity.

Here is the code that registers the custom post type:

function doublee_question() {

$labels = array(
    'name'                  => _x( 'Frequently Asked Questions', 'Post Type General Name', 'doublee' ),
    'singular_name'         => _x( 'Question', 'Post Type Singular Name', 'doublee' ),
    'menu_name'             => __( 'Questions', 'doublee' ),
    'name_admin_bar'        => __( 'Question', 'doublee' ),
    'archives'              => __( 'Question Archives', 'doublee' ),
    'attributes'            => __( 'Question Attributes', 'doublee' ),
    'parent_item_colon'     => __( 'Parent Question:', 'doublee' ),
    'all_items'             => __( 'All Questions', 'doublee' ),
    'add_new_item'          => __( 'Add New Question', 'doublee' ),
    'add_new'               => __( 'Add New', 'doublee' ),
    'new_item'              => __( 'New Question', 'doublee' ),
    'edit_item'             => __( 'Edit Question', 'doublee' ),
    'update_item'           => __( 'Update Question', 'doublee' ),
    'view_item'             => __( 'View Question', 'doublee' ),
    'view_items'            => __( 'View Questions', 'doublee' ),
    'search_items'          => __( 'Search Question', 'doublee' ),
    'not_found'             => __( 'Not found', 'doublee' ),
    'not_found_in_trash'    => __( 'Not found in Trash', 'doublee' ),
    'featured_image'        => __( 'Featured Image', 'doublee' ),
    'set_featured_image'    => __( 'Set featured image', 'doublee' ),
    'remove_featured_image' => __( 'Remove featured image', 'doublee' ),
    'use_featured_image'    => __( 'Use as featured image', 'doublee' ),
    'insert_into_item'      => __( 'Insert into question', 'doublee' ),
    'uploaded_to_this_item' => __( 'Uploaded to this question', 'doublee' ),
    'items_list'            => __( 'Items list', 'doublee' ),
    'items_list_navigation' => __( 'Items list navigation', 'doublee' ),
    'filter_items_list'     => __( 'Filter items list', 'doublee' ),
);
$rewrite = array(
    'slug'                  => 'question',
    'with_front'            => true,
    'pages'                 => true,
    'feeds'                 => true,
);
$args = array(
    'label'                 => __( 'Question', 'doublee' ),
    'description'           => __( 'Frequently Asked Questions', 'doublee' ),
    'labels'                => $labels,
    'supports'              => array( 'title', 'editor', 'revisions', 'page-attributes' ),
    'taxonomies'            => array( 'question_category' ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 9,
    'menu_icon'             => 'dashicons-search',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => 'faq',
    'exclude_from_search'   => false,
    'publicly_queryable'    => true,
    'rewrite'               => $rewrite,
    'capability_type'       => 'post',
);
register_post_type( 'question', $args );

} add_action( 'init', 'doublee_question', 0 );

Other debugging steps that I have tried: * Ensured there's no Page with a slug that clashes with the slug of the archive (i.e. /faq) * Disabled archive-question.php and ensured the FAQ use index.php to rule out the archive template as the source of the issue * Flushed permalinks

3
  • More details needed please. Attach some code snippets from archive-question.php to look into it. Commented May 1, 2018 at 13:52
  • Thanks for your reply! Template code now in the edited question. Commented May 3, 2018 at 0:17
  • Sorry, but questions should be complete without requiring the need to ask again and again for additional information. Here we see you use some non standard pagination function and we still have no idea how that post type is creates.... You have to do some debuging by yourself, localised the issue to some specific code or functionality, and than ask about it. Commented May 3, 2018 at 5:35

1 Answer 1

0

Making the following changes to the CPT registration, and then flushing permalinks, solved the issue:

  1. Changed the rewrite slug to 'faq'
  2. Changed 'has-archive' to true instead of 'faq'

I did #1 so that my archive page URL would still be /faq, and the side effect is that the single questions are now faq/question-name instead of question/question-name but that's ok for this site.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.