WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.