• I’ve created a loop that filters the posts depending on a custom taxonomy called “areas”. This is so that I can have two “home pages” on the same site, displaying posts that are relevant to those areas. All well and good; it works great – until I noticed the posts_nav_link wasn’t displaying anything. I’ve read around the subject, and understand that pagination won’t work on a custom loop – without a workaround – unfortuantely, I don’t have the skills to work it around! If anyone would be willing to have a look at my code and advise me – I’d be very grateful!
    My code:

    <h2 class="section-title">Latest Articles</h2>
    <?php $args = array(
    'post_type' => 'post',
    'tax_query' => array(
    array(
    								'taxonomy' => 'areas',
    								'field'    => 'slug',
    								'terms'    => 'abergavenny',
    								'operator' => 'NOT IN',
    							),
    
    						),
    					);
    $query = new WP_Query( $args ); ?>
    
    <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
    
    <div class="item">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    <p class="date-stamp">Posted on: <?php the_time( 'F jS, Y' ); ?></p>
    <div class="entry">
    <?php the_post_thumbnail('thumbnail'); ?>
    <?php the_excerpt(); ?>
    </div>
    <div class="clear"></div>
    <p class="postmetadata"><?php _e( 'Posted in' ); ?> <em><?php the_category( ', ' ); ?></em></p>
    </div> 
    
    <?php endwhile;
    wp_reset_postdata();
    else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    <div class="navigation">
    <?php posts_nav_link();?><br>
    </div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pagination not working with custom loop’ is closed to new replies.