Next_posts_link() Won't Return Anything When Using Pagination With A WP Posts Query
I've poured over dozens of posts, and the documentation, nothing has helped.
I have a very simple problem: I want to query for all posts of some category, then split up the results into pages. I have tried a few different things, but essentially the next_posts_link() and get_next_posts_link() never returns anything.
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 6, 'paged' => $paged, 'cat' => 135 ); $query = new WP_Query( $args ); ?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?> <div class="med-item talks-texts"> <p class="bold"><?php the_title(); ?> (<?php the_time('Y'); ?>)</p> <?php the_content(); ?> </div> <?php endwhile; endif; ?> <?php next_posts_link(); ?>
Add parameters to the function. In your case:
<?php echo get_next_posts_link('Older', $query->max_num_pages);?> <?php echo get_previous_posts_link('Newer', $query->max_num_pages);?>
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?