I’m trying to output a custom post type archive using a shortcode. Everything works fine except for the get_next_posts_link part. The weird part is that it’s right next to a get_previous_posts_link that works perfectly.
Here’s the function
function output_tips() {
global $paged;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'ht_tips', 'posts_per_page' => 1, 'paged' => $paged, 'caller_get_posts' => 1, 'orderby' => 'date', 'order' => 'DESC' );
$loop = new WP_Query( $args );
$inner = '';
while ( $loop->have_posts() ): $loop->the_post(); global $post;
$title = '<h3>'. get_the_title() .'</h3>';
$content = get_the_content();
$output = '<div class="testimonial">' . $title . $content . '</div>';
$inner .= $output;
endwhile;
$prev = '<div class="nav-previous">' . get_previous_posts_link( __( '<span class="meta-nav">←</span> Previous' ) ) . '</div>';
$next = '<div class="nav-next">' . get_next_posts_link( __( 'Next <span class="meta-nav">→</span>' ) ) . '</div>';
wp_reset_postdata();
$open = '<div class="testimonials">';
$close = '</div>';
$return = $open . $inner . $prev . $next . $close;
return $return;
}
Any idea why this might be?
This is an old question, but I needed the answer to this one as well. Here is the solution taken right from the WP codex…
You need to append the max_num_pages parameter from the query to your output and it should work as expected from within the shortcode.