Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;


$prev = '<div class="nav-previous">' . get_previous_posts_link( __( '<span class="meta-nav">&larr;</span> Previous' ) ) . '</div>';
$next = '<div class="nav-next">' . get_next_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>' ) ) . '</div>';


$open = '<div class="testimonials">';
$close = '</div>';
$return = $open . $inner . $prev . $next . $close;

return $return;

Any idea why this might be?

share|improve this question

1 Answer 1

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...

$prev = '<div class="nav-previous">' . get_next_posts_link( __( '<span class="meta-nav">&larr;</span> Previous' ), $loop->max_num_pages );

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.