Issues with pagination on front page? (3 posts)

  1. Noel Forte
    Posted 2 years ago #


    I'm currently using the following query as suggested by the Codex on my front page:

    <?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    else { $paged = 1; } ?>
    <?php $wp_query = new WP_Query(array(
        'post_type' => array('post', 'portfolio'),
        'posts_per_page' => 5,
        'paged' => $paged
    )); ?>

    However, this query will allow me to navigate from pages 1-3 just fine, but return 404 on page 4, even though $max_num_pages returns 7.

    What am I doing wrong?

  2. keesiemeijer
    Posted 2 years ago #

    Don't use the global query $wp_query. Try it with a new query like this:

    $the_query = new WP_Query( ... );

    You will need to add the max_num_pages to the next_posts_link() function. See this example:

  3. Noel Forte
    Posted 2 years ago #

    The issue fixes itself if I go to Settings > Reading > and set "Front page displays" Use "Static Front Page".

    Is it possible to use front-page.php with Settings > Reading > "Front page displays" set to "Your latest posts"?

    If I set that, what ends up happening is the 4th page (domain.com/page/4) returns a WordPress 404. Why is this happening?

Topic Closed

This topic has been closed to new replies.

About this Topic