posts_nav_link(); not showing up on static pages

I’ve got two different loops. The default on the homepage, but a secondary loop on the archive page. It grabs all the content, like so:

<?php // WP_Query arguments
$args = array (
    'posts_per_page'         => '3'
);
// The Query
$archiveQuery = new WP_Query( $args );

// The Loop
if ( $archiveQuery->have_posts() ) {
    while ( $archiveQuery->have_posts() ) {
        $archiveQuery->the_post(); ?>
        <div class="post">
<a href="<?php the_permalink() ?>">
    <?php  first_item(); ?> </a>

However, when I include posts_nav_link();, it does not show up. Is this because it is a static page? I am using this for an infinite scroll.

Related posts

2 comments

  1. Make sure and include a wp_reset_postdata() at the end of a loop created with WP_Query.

    Use wp_reset_postdata() to restore the global $post variable of the
    main query loop after a secondary query…
    https://codex.wordpress.org/Function_Reference/wp_reset_postdata

    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
        echo '<ul>';
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        }
        echo '</ul>';
    
        /* Restore original Post Data */
        wp_reset_postdata();
    
    } else {
        // no posts found
    }
    

Comments are closed.