I have a problem with adding next and previous links to a single post (I don’t want the next post, I need the next set of posts).
The way the site should work is, the current post is display at the top of the page, and a list of all related posts are displayed below is, with pagination. The query for displaying the related posts is:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'category__in' => $search_categories,
'posts_per_page' => 4,
'paged' => $paged
);
$search_term = null;
if ( isset( $_GET['search_term'] ) ) {
$args['s'] = esc_attr( $_GET['search_term'] );
}
$twp_query = new WP_Query( $args );
I know the query is return enough posts.
Here is the loop (stripped of all markup)
if ( $twp_query->have_posts() ) {
while ( $twp_query->have_posts() ) {
$twp_query->the_post();
get_template_part( 'post', 'listitem' );
}
next_posts_link('Next', $twp_query->max_num_pages);
previous_posts_link('Previous ', $twp_query->max_num_pages);
} else {
_e( 'Apologies, but no results were found.', 'rep' );
}
It display the first 4 items returned, but no next and previous post links are displayed.
I’d appreciate any help, as this one has me stumped!
Update:
Just tried adding ‘nopaging’ => false to the args array, no luck.
Another Update:
Had a look at the WordPress for get_next_posts_link in wp-includes/link-template.php, and judging from this block of code, it is not possible. Unless anybody else knows differently?
if ( !is_single() && ( $nextpage <= $max_page ) ) {
$attr = apply_filters( 'next_posts_link_attributes', '' );
return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>';
}
I’m going to answer this myself then, its not possible due to WordPress’s core, any page that returns true to is_single is blocked from displaying next and previous posts links, one example: