WordPress.org

Ready to get started?Download WordPress

Forums

Issues with pagination on front page? (3 posts)

  1. Noel Forte
    Member
    Posted 9 months ago #

    Hello!

    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
    moderator
    Posted 9 months 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:
    https://codex.wordpress.org/Function_Reference/next_posts_link#Usage_when_querying_the_loop_with_WP_Query

  3. Noel Forte
    Member
    Posted 9 months 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?

Reply

You must log in to post.

About this Topic